From 7cd76a1bb0032935b721b9c49ef984095c5b39a6 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Thu, 29 Sep 2022 13:51:09 +0200 Subject: [PATCH] chore: Add _fluttefire_internals and extract firebase_core/src/internals to the new package (#9628) --- packages/_flutterfire_internals/CHANGELOG.md | 3 ++ packages/_flutterfire_internals/LICENSE | 26 +++++++++ packages/_flutterfire_internals/README.md | 4 ++ .../lib/_flutterfire_internals.dart} | 25 ++++++++- .../lib/src/exception.dart | 53 +++++++++++++++++++ .../lib/src/interop_shimmer.dart | 0 packages/_flutterfire_internals/pubspec.yaml | 25 +++++++++ .../test/guard_test.dart | 4 +- .../cloud_firestore/example/pubspec.yaml | 2 + .../src/method_channel/utils/exception.dart | 34 ++---------- .../pubspec.yaml | 1 + .../lib/src/internals.dart | 7 +-- .../cloud_firestore_web/pubspec.yaml | 1 + .../cloud_firestore_odm/example/pubspec.yaml | 2 + .../pubspec.yaml | 2 + .../cloud_functions/example/pubspec.yaml | 2 + .../firebase_analytics/example/pubspec.yaml | 2 + .../src/method_channel/utils/exception.dart | 37 ++----------- .../pubspec.yaml | 1 + .../lib/utils/exception.dart | 6 +-- .../firebase_analytics_web/pubspec.yaml | 1 + .../firebase_app_check/example/pubspec.yaml | 2 + .../method_channel_firebase_app_check.dart | 6 +-- .../src/method_channel/utils/exception.dart | 45 ++++------------ .../pubspec.yaml | 1 + .../lib/src/internals.dart | 6 +-- .../firebase_app_check_web/pubspec.yaml | 1 + .../example/pubspec.yaml | 2 + .../src/method_channel/utils/exception.dart | 38 ++----------- .../pubspec.yaml | 1 + .../lib/src/guard.dart | 6 +-- .../pubspec.yaml | 1 + .../firebase_auth/example/pubspec.yaml | 2 + .../firebase_crashlytics/example/pubspec.yaml | 2 + .../method_channel_crashlytics.dart | 20 +++---- .../src/method_channel/utils/exception.dart | 43 +++------------ .../pubspec.yaml | 1 + .../firebase_database/example/pubspec.yaml | 2 + .../src/method_channel/utils/exception.dart | 38 ++----------- .../pubspec.yaml | 1 + .../example/pubspec.yaml | 2 + .../src/method_channel/utils/exception.dart | 38 ++----------- .../pubspec.yaml | 1 + .../example/pubspec.yaml | 2 + .../src/method_channel/utils/exception.dart | 38 ++----------- .../pubspec.yaml | 1 + .../firebase_messaging/example/pubspec.yaml | 2 + .../src/method_channel/utils/exception.dart | 43 +++------------ .../pubspec.yaml | 1 + .../lib/src/internals.dart | 7 +-- .../firebase_messaging_web/pubspec.yaml | 1 + .../example/pubspec.yaml | 2 + .../firebase_performance/example/pubspec.yaml | 2 + .../src/method_channel/utils/exception.dart | 43 +++------------ .../pubspec.yaml | 1 + .../lib/src/internals.dart | 6 +-- .../firebase_performance_web/pubspec.yaml | 1 + .../example/pubspec.yaml | 2 + .../src/method_channel/utils/exception.dart | 43 +++------------ .../pubspec.yaml | 1 + .../firebase_storage/example/pubspec.yaml | 2 + .../lib/src/utils/errors.dart | 4 +- .../firebase_storage_web/pubspec.yaml | 1 + tests/pubspec.yaml | 2 + 64 files changed, 277 insertions(+), 425 deletions(-) create mode 100644 packages/_flutterfire_internals/CHANGELOG.md create mode 100644 packages/_flutterfire_internals/LICENSE create mode 100755 packages/_flutterfire_internals/README.md rename packages/{firebase_core/firebase_core/lib/src/internals.dart => _flutterfire_internals/lib/_flutterfire_internals.dart} (84%) create mode 100644 packages/_flutterfire_internals/lib/src/exception.dart rename packages/{firebase_core/firebase_core => _flutterfire_internals}/lib/src/interop_shimmer.dart (100%) create mode 100755 packages/_flutterfire_internals/pubspec.yaml rename packages/{firebase_core/firebase_core => _flutterfire_internals}/test/guard_test.dart (92%) diff --git a/packages/_flutterfire_internals/CHANGELOG.md b/packages/_flutterfire_internals/CHANGELOG.md new file mode 100644 index 000000000000..c39fe225caf5 --- /dev/null +++ b/packages/_flutterfire_internals/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +Initial release of \_fluttefire_internals diff --git a/packages/_flutterfire_internals/LICENSE b/packages/_flutterfire_internals/LICENSE new file mode 100644 index 000000000000..5b8ff6261110 --- /dev/null +++ b/packages/_flutterfire_internals/LICENSE @@ -0,0 +1,26 @@ +Copyright 2017, the Chromium project authors. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/_flutterfire_internals/README.md b/packages/_flutterfire_internals/README.md new file mode 100755 index 000000000000..896d3a975016 --- /dev/null +++ b/packages/_flutterfire_internals/README.md @@ -0,0 +1,4 @@ +# \_flutterfire_internals + +This package is hosting Dart code shared between FlutterFire plugins. It is not +meant for public consumption. \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/lib/src/internals.dart b/packages/_flutterfire_internals/lib/_flutterfire_internals.dart similarity index 84% rename from packages/firebase_core/firebase_core/lib/src/internals.dart rename to packages/_flutterfire_internals/lib/_flutterfire_internals.dart index 2969fb8b9873..041953aacbd5 100644 --- a/packages/firebase_core/firebase_core/lib/src/internals.dart +++ b/packages/_flutterfire_internals/lib/_flutterfire_internals.dart @@ -7,17 +7,38 @@ // This file exports utilities shared between firebase packages, without making // them public. -import '../firebase_core.dart'; -import 'interop_shimmer.dart' +import 'package:firebase_core/firebase_core.dart'; +import 'src/interop_shimmer.dart' if (dart.library.js) 'package:firebase_core_web/firebase_core_web_interop.dart' as core_interop; +export 'src/exception.dart'; + +/// An extension that adds utilities for safely casting objects extension ObjectX on T? { + /// Transform an object if that value is not null. + /// + /// Doing: + /// + /// ```dart + /// Map? json; + /// var result = json?['key']?.guard((json) => Model.fromJson(json)); + /// ``` + /// + /// is equivalent to doing: + /// + /// ```dart + /// Map? json; + /// var key = json?['key']; + /// var result = key == null ? null : Model.fromJson(key); + /// ``` R? guard(R Function(T value) cb) { if (this is T) return cb(this as T); return null; } + /// Safely cast an object, returning `null` if the casted object does not + /// match the casted type. R? safeCast() { if (this is R) return this as R; return null; diff --git a/packages/_flutterfire_internals/lib/src/exception.dart b/packages/_flutterfire_internals/lib/src/exception.dart new file mode 100644 index 000000000000..a6426c178751 --- /dev/null +++ b/packages/_flutterfire_internals/lib/src/exception.dart @@ -0,0 +1,53 @@ +// ignore_for_file: require_trailing_commas +// Copyright 2020, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:firebase_core/firebase_core.dart'; +import 'package:flutter/services.dart'; + +/// Catches a [PlatformException] and returns an [Exception]. +/// +/// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. +Never convertPlatformExceptionToFirebaseException( + Object exception, + StackTrace stackTrace, { + required String plugin, +}) { + if (exception is! Exception || exception is! PlatformException) { + Error.throwWithStackTrace(exception, stackTrace); + } + + Error.throwWithStackTrace( + platformExceptionToFirebaseException(exception, plugin: plugin), + stackTrace, + ); +} + +/// Converts a [PlatformException] into a [FirebaseException]. +/// +/// A [PlatformException] can only be converted to a [FirebaseException] if the +/// `details` of the exception exist. Firebase returns specific codes and messages +/// which can be converted into user friendly exceptions. +FirebaseException platformExceptionToFirebaseException( + PlatformException platformException, { + required String plugin, +}) { + Map? details = platformException.details != null + ? Map.from(platformException.details) + : null; + + String? code; + String message = platformException.message ?? ''; + + if (details != null) { + code = details['code'] ?? code; + message = details['message'] ?? message; + } + + return FirebaseException( + plugin: plugin, + code: code, + message: message, + ); +} diff --git a/packages/firebase_core/firebase_core/lib/src/interop_shimmer.dart b/packages/_flutterfire_internals/lib/src/interop_shimmer.dart similarity index 100% rename from packages/firebase_core/firebase_core/lib/src/interop_shimmer.dart rename to packages/_flutterfire_internals/lib/src/interop_shimmer.dart diff --git a/packages/_flutterfire_internals/pubspec.yaml b/packages/_flutterfire_internals/pubspec.yaml new file mode 100755 index 000000000000..70267bc378d0 --- /dev/null +++ b/packages/_flutterfire_internals/pubspec.yaml @@ -0,0 +1,25 @@ +name: _flutterfire_internals +description: A package hosting Dart code shared between FlutterFire plugins. +homepage: https://firebase.google.com/docs/firestore +repository: https://github.com/firebase/flutterfire/tree/master/packages/_flutterfire_internals +version: 1.0.0 + +environment: + sdk: '>=2.16.0 <3.0.0' + flutter: '>=1.12.13+hotfix.5' + +dependencies: + cloud_firestore_platform_interface: ^5.7.5 + cloud_firestore_web: ^2.8.8 + collection: ^1.0.0 + firebase_core: ^1.10.2 + firebase_core_platform_interface: ^4.5.1 + flutter: + sdk: flutter + meta: ^1.3.0 + +dev_dependencies: + flutter_test: + sdk: flutter + mockito: ^5.0.0 + test: any diff --git a/packages/firebase_core/firebase_core/test/guard_test.dart b/packages/_flutterfire_internals/test/guard_test.dart similarity index 92% rename from packages/firebase_core/firebase_core/test/guard_test.dart rename to packages/_flutterfire_internals/test/guard_test.dart index 75202f60bcc0..b0a6af08af29 100644 --- a/packages/firebase_core/firebase_core/test/guard_test.dart +++ b/packages/_flutterfire_internals/test/guard_test.dart @@ -1,5 +1,5 @@ -import 'package:firebase_core/src/internals.dart'; -import 'package:firebase_core/src/interop_shimmer.dart'; +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; +import 'package:_flutterfire_internals/src/interop_shimmer.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/cloud_firestore/cloud_firestore/example/pubspec.yaml b/packages/cloud_firestore/cloud_firestore/example/pubspec.yaml index f27a61bb7f69..66b36d0f8a04 100755 --- a/packages/cloud_firestore/cloud_firestore/example/pubspec.yaml +++ b/packages/cloud_firestore/cloud_firestore/example/pubspec.yaml @@ -15,6 +15,8 @@ dependencies: http: ^0.13.3 dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals cloud_firestore_platform_interface: path: ../../cloud_firestore_platform_interface cloud_firestore_web: diff --git a/packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/method_channel/utils/exception.dart index 7c87b0dff169..17bc9d82ae35 100644 --- a/packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/method_channel/utils/exception.dart @@ -1,44 +1,18 @@ -// ignore_for_file: require_trailing_commas // Copyright 2020, the Chromium project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. import 'package:firebase_core/firebase_core.dart'; +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; import 'package:flutter/services.dart'; /// Catches a [PlatformException] and returns an [Exception]. /// /// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. Never convertPlatformException(Object exception, StackTrace stackTrace) { - if (exception is! Exception || exception is! PlatformException) { - Error.throwWithStackTrace(exception, stackTrace); - } - - Error.throwWithStackTrace( - platformExceptionToFirebaseException(exception), + convertPlatformExceptionToFirebaseException( + exception, stackTrace, + plugin: 'cloud_firestore', ); } - -/// Converts a [PlatformException] into a [FirebaseException]. -/// -/// A [PlatformException] can only be converted to a [FirebaseException] if the -/// `details` of the exception exist. Firebase returns specific codes and messages -/// which can be converted into user friendly exceptions. -FirebaseException platformExceptionToFirebaseException( - PlatformException platformException) { - Map? details = platformException.details != null - ? Map.from(platformException.details) - : null; - - String code = 'unknown'; - String message = platformException.message ?? ''; - - if (details != null) { - code = details['code'] ?? code; - message = details['message'] ?? message; - } - - return FirebaseException( - plugin: 'cloud_firestore', code: code, message: message); -} diff --git a/packages/cloud_firestore/cloud_firestore_platform_interface/pubspec.yaml b/packages/cloud_firestore/cloud_firestore_platform_interface/pubspec.yaml index 5569cce9057d..e9df3ed580ee 100644 --- a/packages/cloud_firestore/cloud_firestore_platform_interface/pubspec.yaml +++ b/packages/cloud_firestore/cloud_firestore_platform_interface/pubspec.yaml @@ -9,6 +9,7 @@ environment: flutter: ">=1.9.1+hotfix.5" dependencies: + _flutterfire_internals: ^1.0.0 collection: ^1.15.0 firebase_core: ^1.10.0 flutter: diff --git a/packages/cloud_firestore/cloud_firestore_web/lib/src/internals.dart b/packages/cloud_firestore/cloud_firestore_web/lib/src/internals.dart index 9084af7cdfb3..eddfe5875967 100644 --- a/packages/cloud_firestore/cloud_firestore_web/lib/src/internals.dart +++ b/packages/cloud_firestore/cloud_firestore_web/lib/src/internals.dart @@ -1,9 +1,6 @@ -// ignore_for_file: require_trailing_commas -export 'package:firebase_core/src/internals.dart' hide guardWebExceptions; - import 'package:firebase_core/firebase_core.dart'; -// ignore: implementation_imports -import 'package:firebase_core/src/internals.dart' as internals; +import 'package:_flutterfire_internals/_flutterfire_internals.dart' + as internals; /// Will return a [FirebaseException] from a thrown web error. /// Any other errors will be propagated as normal. diff --git a/packages/cloud_firestore/cloud_firestore_web/pubspec.yaml b/packages/cloud_firestore/cloud_firestore_web/pubspec.yaml index f6a38b54d6f9..4105fde9fda7 100644 --- a/packages/cloud_firestore/cloud_firestore_web/pubspec.yaml +++ b/packages/cloud_firestore/cloud_firestore_web/pubspec.yaml @@ -10,6 +10,7 @@ environment: flutter: ">=1.12.13+hotfix.4" dependencies: + _flutterfire_internals: ^1.0.0 cloud_firestore_platform_interface: ^5.7.5 collection: ^1.0.0 firebase_core: ^1.10.0 diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/pubspec.yaml b/packages/cloud_firestore_odm/cloud_firestore_odm/example/pubspec.yaml index 8fd4b219bde7..21affb6e499f 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/pubspec.yaml +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/pubspec.yaml @@ -32,6 +32,8 @@ dev_dependencies: mockito: ^5.0.0 dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals cloud_firestore: path: ../../../cloud_firestore/cloud_firestore cloud_firestore_odm: diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/pubspec.yaml b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/pubspec.yaml index 1c0506224fb7..4935e34dc238 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/pubspec.yaml +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/pubspec.yaml @@ -25,6 +25,8 @@ dev_dependencies: json_serializable: ">=6.3.0 <7.0.0" dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals cloud_firestore: path: ../../../cloud_firestore/cloud_firestore cloud_firestore_odm: diff --git a/packages/cloud_functions/cloud_functions/example/pubspec.yaml b/packages/cloud_functions/cloud_functions/example/pubspec.yaml index cb7a3e0ca55b..41b9b64c1115 100644 --- a/packages/cloud_functions/cloud_functions/example/pubspec.yaml +++ b/packages/cloud_functions/cloud_functions/example/pubspec.yaml @@ -15,6 +15,8 @@ dependencies: sdk: flutter dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals cloud_functions_platform_interface: path: ../../../cloud_functions/cloud_functions_platform_interface cloud_functions_web: diff --git a/packages/firebase_analytics/firebase_analytics/example/pubspec.yaml b/packages/firebase_analytics/firebase_analytics/example/pubspec.yaml index dfaa3ab23cd1..7c231aea4ce9 100755 --- a/packages/firebase_analytics/firebase_analytics/example/pubspec.yaml +++ b/packages/firebase_analytics/firebase_analytics/example/pubspec.yaml @@ -14,6 +14,8 @@ dependencies: sdk: flutter dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_analytics_platform_interface: path: ../../firebase_analytics_platform_interface firebase_analytics_web: diff --git a/packages/firebase_analytics/firebase_analytics_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_analytics/firebase_analytics_platform_interface/lib/src/method_channel/utils/exception.dart index baca0aebb04b..e0e12bcc3ca6 100644 --- a/packages/firebase_analytics/firebase_analytics_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_analytics/firebase_analytics_platform_interface/lib/src/method_channel/utils/exception.dart @@ -3,47 +3,16 @@ // found in the LICENSE file. import 'package:firebase_core/firebase_core.dart' show FirebaseException; +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; import 'package:flutter/services.dart'; /// Catches a [PlatformException] and returns an [Exception]. /// /// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. Never convertPlatformException(Object exception, StackTrace stackTrace) { - if (exception is! Exception || exception is! PlatformException) { - Error.throwWithStackTrace(exception, stackTrace); - } - - Error.throwWithStackTrace( - platformExceptionToFirebaseException(exception, stackTrace), + convertPlatformExceptionToFirebaseException( + exception, stackTrace, - ); -} - -/// Converts a [PlatformException] into a [FirebaseException]. -/// -/// A [PlatformException] can only be converted to a [FirebaseException] if the -/// `details` of the exception exist. Firebase returns specific codes and messages -/// which can be converted into user friendly exceptions. -FirebaseException platformExceptionToFirebaseException( - PlatformException platformException, - StackTrace stackTrace, -) { - Map? details = platformException.details != null - ? Map.from(platformException.details) - : null; - - String code = 'unknown'; - String message = platformException.message ?? ''; - - if (details != null) { - code = details['code'] ?? code; - message = details['message'] ?? message; - } - - return FirebaseException( plugin: 'firebase_analytics', - code: code, - message: message, - stackTrace: stackTrace, ); } diff --git a/packages/firebase_analytics/firebase_analytics_platform_interface/pubspec.yaml b/packages/firebase_analytics/firebase_analytics_platform_interface/pubspec.yaml index dec4d9776b1c..44b907a7ff5d 100644 --- a/packages/firebase_analytics/firebase_analytics_platform_interface/pubspec.yaml +++ b/packages/firebase_analytics/firebase_analytics_platform_interface/pubspec.yaml @@ -9,6 +9,7 @@ environment: flutter: '>=1.9.1+hotfix.5' dependencies: + _flutterfire_internals: ^1.0.0 firebase_core: ^1.10.0 flutter: sdk: flutter diff --git a/packages/firebase_analytics/firebase_analytics_web/lib/utils/exception.dart b/packages/firebase_analytics/firebase_analytics_web/lib/utils/exception.dart index 25b6eae9fef2..7be844cda673 100644 --- a/packages/firebase_analytics/firebase_analytics_web/lib/utils/exception.dart +++ b/packages/firebase_analytics/firebase_analytics_web/lib/utils/exception.dart @@ -1,8 +1,6 @@ -export 'package:firebase_core/src/internals.dart' hide guardWebExceptions; - import 'package:firebase_core/firebase_core.dart'; -// ignore: implementation_imports -import 'package:firebase_core/src/internals.dart' as internals; +import 'package:_flutterfire_internals/_flutterfire_internals.dart' + as internals; /// Will return a [FirebaseException] from a thrown web error. /// Any other errors will be propagated as normal. diff --git a/packages/firebase_analytics/firebase_analytics_web/pubspec.yaml b/packages/firebase_analytics/firebase_analytics_web/pubspec.yaml index f2b5af02ee60..6ce12b9f9d97 100644 --- a/packages/firebase_analytics/firebase_analytics_web/pubspec.yaml +++ b/packages/firebase_analytics/firebase_analytics_web/pubspec.yaml @@ -9,6 +9,7 @@ environment: flutter: '>=1.12.13+hotfix.4' dependencies: + _flutterfire_internals: ^1.0.0 firebase_analytics_platform_interface: ^3.3.5 firebase_core: ^1.10.0 firebase_core_web: ^1.7.2 diff --git a/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml b/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml index fe05279cabfa..f6ba445a6db5 100644 --- a/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml +++ b/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml @@ -20,6 +20,8 @@ dependencies: sdk: flutter dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals cloud_firestore: path: ../../../cloud_firestore/cloud_firestore cloud_firestore_platform_interface: diff --git a/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/method_channel/method_channel_firebase_app_check.dart b/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/method_channel/method_channel_firebase_app_check.dart index 1c82f9bd6962..a975f903a968 100644 --- a/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/method_channel/method_channel_firebase_app_check.dart +++ b/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/method_channel/method_channel_firebase_app_check.dart @@ -82,7 +82,7 @@ class MethodChannelFirebaseAppCheck extends FirebaseAppCheckPlatform { 'androidDebugProvider': androidDebugProvider, }); } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } @@ -96,7 +96,7 @@ class MethodChannelFirebaseAppCheck extends FirebaseAppCheckPlatform { return result!['token']; } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } @@ -113,7 +113,7 @@ class MethodChannelFirebaseAppCheck extends FirebaseAppCheckPlatform { }, ); } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } diff --git a/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/method_channel/utils/exception.dart index 62235d8387b3..7bfe0da145a4 100644 --- a/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/method_channel/utils/exception.dart @@ -6,44 +6,17 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; -/// Catches a [PlatformException] and converts it into a [FirebaseException] if -/// it was intentionally caught on the native platform. -Never convertPlatformException(Object exception, StackTrace stackTrace) { - if (exception is! Exception || exception is! PlatformException) { - Error.throwWithStackTrace(exception, stackTrace); - } +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; - Error.throwWithStackTrace( - platformExceptionToFirebaseException(exception, stackTrace), - stackTrace, - ); -} +const pluginName = 'firebase_app_check'; -/// Converts a [PlatformException] into a [FirebaseException]. +/// Catches a [PlatformException] and returns an [Exception]. /// -/// A [PlatformException] can only be converted to a [FirebaseException] if the -/// `details` of the exception exist. Firebase returns specific codes and messages -/// which can be converted into user friendly exceptions. -FirebaseException platformExceptionToFirebaseException( - PlatformException platformException, - StackTrace stackTrace, -) { - Map? details = platformException.details != null - ? Map.from(platformException.details) - : null; - - String code = 'unknown'; - String message = platformException.message ?? ''; - - if (details != null) { - code = details['code'] ?? code; - message = details['message'] ?? message; - } - - return FirebaseException( - plugin: 'firebase_app_check', - code: code, - message: message, - stackTrace: stackTrace, +/// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. +Never convertPlatformException(Object exception, StackTrace stackTrace) { + convertPlatformExceptionToFirebaseException( + exception, + stackTrace, + plugin: pluginName, ); } diff --git a/packages/firebase_app_check/firebase_app_check_platform_interface/pubspec.yaml b/packages/firebase_app_check/firebase_app_check_platform_interface/pubspec.yaml index 228571aec7ab..e597e51c1c84 100644 --- a/packages/firebase_app_check/firebase_app_check_platform_interface/pubspec.yaml +++ b/packages/firebase_app_check/firebase_app_check_platform_interface/pubspec.yaml @@ -8,6 +8,7 @@ environment: flutter: ">=1.20.0" dependencies: + _flutterfire_internals: ^1.0.0 firebase_core: ^1.10.0 flutter: sdk: flutter diff --git a/packages/firebase_app_check/firebase_app_check_web/lib/src/internals.dart b/packages/firebase_app_check/firebase_app_check_web/lib/src/internals.dart index 18b49e6d69b7..9196b2cfaf04 100644 --- a/packages/firebase_app_check/firebase_app_check_web/lib/src/internals.dart +++ b/packages/firebase_app_check/firebase_app_check_web/lib/src/internals.dart @@ -2,11 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -export 'package:firebase_core/src/internals.dart' hide guardWebExceptions; - import 'package:firebase_core/firebase_core.dart'; -// ignore: implementation_imports -import 'package:firebase_core/src/internals.dart' as internals; +import 'package:_flutterfire_internals/_flutterfire_internals.dart' + as internals; /// Will return a [FirebaseException] from a thrown web error. /// Any other errors will be propagated as normal. diff --git a/packages/firebase_app_check/firebase_app_check_web/pubspec.yaml b/packages/firebase_app_check/firebase_app_check_web/pubspec.yaml index 07bb9286b2b0..6cfa49c76172 100644 --- a/packages/firebase_app_check/firebase_app_check_web/pubspec.yaml +++ b/packages/firebase_app_check/firebase_app_check_web/pubspec.yaml @@ -8,6 +8,7 @@ environment: flutter: ">=1.20.0" dependencies: + _flutterfire_internals: ^1.0.0 firebase_app_check_platform_interface: ^0.0.4+17 firebase_core: ^1.10.0 firebase_core_web: ^1.7.2 diff --git a/packages/firebase_app_installations/firebase_app_installations/example/pubspec.yaml b/packages/firebase_app_installations/firebase_app_installations/example/pubspec.yaml index a58df8802057..3716351b3531 100644 --- a/packages/firebase_app_installations/firebase_app_installations/example/pubspec.yaml +++ b/packages/firebase_app_installations/firebase_app_installations/example/pubspec.yaml @@ -34,6 +34,8 @@ dependencies: sdk: flutter dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_core: path: ../../../firebase_core/firebase_core firebase_app_installations_web: diff --git a/packages/firebase_app_installations/firebase_app_installations_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_app_installations/firebase_app_installations_platform_interface/lib/src/method_channel/utils/exception.dart index 471280d2f515..d70a53b48bb4 100644 --- a/packages/firebase_app_installations/firebase_app_installations_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_app_installations/firebase_app_installations_platform_interface/lib/src/method_channel/utils/exception.dart @@ -5,45 +5,15 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; + /// Catches a [PlatformException] and returns an [Exception]. /// /// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. Never convertPlatformException(Object exception, StackTrace stackTrace) { - if (exception is! Exception || exception is! PlatformException) { - Error.throwWithStackTrace(exception, stackTrace); - } - - Error.throwWithStackTrace( - platformExceptionToFirebaseException(exception, stackTrace), + convertPlatformExceptionToFirebaseException( + exception, stackTrace, - ); -} - -/// Converts a [PlatformException] into a [FirebaseException]. -/// -/// A [PlatformException] can only be converted to a [FirebaseException] if the -/// `details` of the exception exist. Firebase returns specific codes and messages -/// which can be converted into user friendly exceptions. -FirebaseException platformExceptionToFirebaseException( - PlatformException platformException, - StackTrace stackTrace, -) { - Map? details = platformException.details != null - ? Map.from(platformException.details) - : null; - - String code = 'unknown'; - String message = platformException.message ?? ''; - - if (details != null) { - code = details['code'] ?? code; - message = details['message'] ?? message; - } - - return FirebaseException( plugin: 'firebase_app_installations', - code: code, - message: message, - stackTrace: stackTrace, ); } diff --git a/packages/firebase_app_installations/firebase_app_installations_platform_interface/pubspec.yaml b/packages/firebase_app_installations/firebase_app_installations_platform_interface/pubspec.yaml index c9e2c6519443..743e30719244 100644 --- a/packages/firebase_app_installations/firebase_app_installations_platform_interface/pubspec.yaml +++ b/packages/firebase_app_installations/firebase_app_installations_platform_interface/pubspec.yaml @@ -9,6 +9,7 @@ environment: flutter: ">=1.17.0" dependencies: + _flutterfire_internals: ^1.0.0 firebase_core: ^1.10.0 flutter: sdk: flutter diff --git a/packages/firebase_app_installations/firebase_app_installations_web/lib/src/guard.dart b/packages/firebase_app_installations/firebase_app_installations_web/lib/src/guard.dart index 24da8c1da15a..b4e7219e6186 100644 --- a/packages/firebase_app_installations/firebase_app_installations_web/lib/src/guard.dart +++ b/packages/firebase_app_installations/firebase_app_installations_web/lib/src/guard.dart @@ -4,10 +4,8 @@ import 'package:firebase_core/firebase_core.dart'; -// ignore: implementation_imports -import 'package:firebase_core/src/internals.dart' as internals; - -export 'package:firebase_core/src/internals.dart' hide guardWebExceptions; +import 'package:_flutterfire_internals/_flutterfire_internals.dart' + as internals; /// Will return a [FirebaseException] from a thrown web error. /// Any other errors will be propagated as normal. diff --git a/packages/firebase_app_installations/firebase_app_installations_web/pubspec.yaml b/packages/firebase_app_installations/firebase_app_installations_web/pubspec.yaml index 8e2b066dd66a..5854e58d2ed3 100644 --- a/packages/firebase_app_installations/firebase_app_installations_web/pubspec.yaml +++ b/packages/firebase_app_installations/firebase_app_installations_web/pubspec.yaml @@ -9,6 +9,7 @@ environment: flutter: '>=1.20.0' dependencies: + _flutterfire_internals: ^1.0.0 firebase_app_installations_platform_interface: ^0.1.1+17 firebase_core: ^1.10.0 firebase_core_web: ^1.7.2 diff --git a/packages/firebase_auth/firebase_auth/example/pubspec.yaml b/packages/firebase_auth/firebase_auth/example/pubspec.yaml index 9e413dcf45e2..cc055d9349ea 100644 --- a/packages/firebase_auth/firebase_auth/example/pubspec.yaml +++ b/packages/firebase_auth/firebase_auth/example/pubspec.yaml @@ -15,6 +15,8 @@ dependencies: google_sign_in: ^5.1.0 dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_auth: path: ../ firebase_auth_platform_interface: diff --git a/packages/firebase_crashlytics/firebase_crashlytics/example/pubspec.yaml b/packages/firebase_crashlytics/firebase_crashlytics/example/pubspec.yaml index 17cfeeedf69c..a117221f7b83 100644 --- a/packages/firebase_crashlytics/firebase_crashlytics/example/pubspec.yaml +++ b/packages/firebase_crashlytics/firebase_crashlytics/example/pubspec.yaml @@ -16,6 +16,8 @@ dependencies: sdk: flutter dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_core: path: ../../../firebase_core/firebase_core firebase_core_platform_interface: diff --git a/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/lib/src/method_channel/method_channel_crashlytics.dart b/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/lib/src/method_channel/method_channel_crashlytics.dart index 74ed378293b8..b8321ae19160 100644 --- a/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/lib/src/method_channel/method_channel_crashlytics.dart +++ b/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/lib/src/method_channel/method_channel_crashlytics.dart @@ -53,7 +53,7 @@ class MethodChannelFirebaseCrashlytics extends FirebaseCrashlyticsPlatform { return data!['unsentReports']; } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } @@ -62,7 +62,7 @@ class MethodChannelFirebaseCrashlytics extends FirebaseCrashlyticsPlatform { try { await channel.invokeMethod('Crashlytics#crash'); } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } @@ -71,7 +71,7 @@ class MethodChannelFirebaseCrashlytics extends FirebaseCrashlyticsPlatform { try { await channel.invokeMethod('Crashlytics#deleteUnsentReports'); } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } @@ -84,7 +84,7 @@ class MethodChannelFirebaseCrashlytics extends FirebaseCrashlyticsPlatform { return data!['didCrashOnPreviousExecution']; } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } @@ -106,7 +106,7 @@ class MethodChannelFirebaseCrashlytics extends FirebaseCrashlyticsPlatform { 'stackTraceElements': stackTraceElements ?? [], }); } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } @@ -117,7 +117,7 @@ class MethodChannelFirebaseCrashlytics extends FirebaseCrashlyticsPlatform { 'message': message, }); } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } @@ -126,7 +126,7 @@ class MethodChannelFirebaseCrashlytics extends FirebaseCrashlyticsPlatform { try { await channel.invokeMethod('Crashlytics#sendUnsentReports'); } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } @@ -141,7 +141,7 @@ class MethodChannelFirebaseCrashlytics extends FirebaseCrashlyticsPlatform { _isCrashlyticsCollectionEnabled = data!['isCrashlyticsCollectionEnabled']; } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } @@ -153,7 +153,7 @@ class MethodChannelFirebaseCrashlytics extends FirebaseCrashlyticsPlatform { 'identifier': identifier, }); } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } @@ -166,7 +166,7 @@ class MethodChannelFirebaseCrashlytics extends FirebaseCrashlyticsPlatform { 'value': value, }); } on PlatformException catch (e, s) { - throw platformExceptionToFirebaseException(e, s); + convertPlatformException(e, s); } } } diff --git a/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/lib/src/method_channel/utils/exception.dart index 90eb6e6748fb..810ac53044f7 100644 --- a/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/lib/src/method_channel/utils/exception.dart @@ -6,44 +6,15 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; -/// Catches a [PlatformException] and converts it into a [FirebaseException] if -/// it was intentionally caught on the native platform. -Never convertPlatformException(Object exception, StackTrace stackTrace) { - if (exception is! Exception || exception is! PlatformException) { - Error.throwWithStackTrace(exception, stackTrace); - } - - Error.throwWithStackTrace( - platformExceptionToFirebaseException(exception, stackTrace), - stackTrace, - ); -} +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; -/// Converts a [PlatformException] into a [FirebaseException]. +/// Catches a [PlatformException] and returns an [Exception]. /// -/// A [PlatformException] can only be converted to a [FirebaseException] if the -/// `details` of the exception exist. Firebase returns specific codes and messages -/// which can be converted into user friendly exceptions. -FirebaseException platformExceptionToFirebaseException( - PlatformException platformException, - StackTrace stackTrace, -) { - Map? details = platformException.details != null - ? Map.from(platformException.details) - : null; - - String code = 'unknown'; - String message = platformException.message ?? ''; - - if (details != null) { - code = details['code'] ?? code; - message = details['message'] ?? message; - } - - return FirebaseException( +/// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. +Never convertPlatformException(Object exception, StackTrace stackTrace) { + convertPlatformExceptionToFirebaseException( + exception, + stackTrace, plugin: 'firebase_crashlytics', - code: code, - message: message, - stackTrace: stackTrace, ); } diff --git a/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/pubspec.yaml b/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/pubspec.yaml index ab7c808fe1d1..3232bb503a5a 100644 --- a/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/pubspec.yaml +++ b/packages/firebase_crashlytics/firebase_crashlytics_platform_interface/pubspec.yaml @@ -9,6 +9,7 @@ environment: flutter: ">=1.12.13+hotfix.5" dependencies: + _flutterfire_internals: ^1.0.0 collection: ^1.15.0 firebase_core: ^1.10.0 flutter: diff --git a/packages/firebase_database/firebase_database/example/pubspec.yaml b/packages/firebase_database/firebase_database/example/pubspec.yaml index 1b81b1b63bc0..eb9d688c55c4 100755 --- a/packages/firebase_database/firebase_database/example/pubspec.yaml +++ b/packages/firebase_database/firebase_database/example/pubspec.yaml @@ -14,6 +14,8 @@ dependencies: sdk: flutter dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_core: path: ../../../firebase_core/firebase_core firebase_core_platform_interface: diff --git a/packages/firebase_database/firebase_database_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_database/firebase_database_platform_interface/lib/src/method_channel/utils/exception.dart index 565b6a017609..cd09b58be72f 100644 --- a/packages/firebase_database/firebase_database_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_database/firebase_database_platform_interface/lib/src/method_channel/utils/exception.dart @@ -5,45 +5,15 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; + /// Catches a [PlatformException] and returns an [Exception]. /// /// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. Never convertPlatformException(Object exception, StackTrace stackTrace) { - if (exception is! Exception || exception is! PlatformException) { - Error.throwWithStackTrace(exception, stackTrace); - } - - Error.throwWithStackTrace( - platformExceptionToFirebaseException(exception, stackTrace), + convertPlatformExceptionToFirebaseException( + exception, stackTrace, - ); -} - -/// Converts a [PlatformException] into a [FirebaseException]. -/// -/// A [PlatformException] can only be converted to a [FirebaseException] if the -/// `details` of the exception exist. Firebase returns specific codes and messages -/// which can be converted into user friendly exceptions. -FirebaseException platformExceptionToFirebaseException( - PlatformException platformException, - StackTrace stackTrace, -) { - Map? details = platformException.details != null - ? Map.from(platformException.details) - : null; - - String code = 'unknown'; - String message = platformException.message ?? ''; - - if (details != null) { - code = details['code'] ?? code; - message = details['message'] ?? message; - } - - return FirebaseException( plugin: 'firebase_database', - code: code, - message: message, - stackTrace: stackTrace, ); } diff --git a/packages/firebase_database/firebase_database_platform_interface/pubspec.yaml b/packages/firebase_database/firebase_database_platform_interface/pubspec.yaml index 44d0834dfe2c..a6e655b689f4 100755 --- a/packages/firebase_database/firebase_database_platform_interface/pubspec.yaml +++ b/packages/firebase_database/firebase_database_platform_interface/pubspec.yaml @@ -4,6 +4,7 @@ version: 0.2.2+5 homepage: https://github.com/firebase/flutterfire/tree/master/packages/firebase_database/firebase_database_platform_interface dependencies: + _flutterfire_internals: ^1.0.0 collection: ^1.14.3 firebase_core: ^1.10.0 flutter: diff --git a/packages/firebase_dynamic_links/firebase_dynamic_links/example/pubspec.yaml b/packages/firebase_dynamic_links/firebase_dynamic_links/example/pubspec.yaml index 7892b8c7584d..afa3f3f1143c 100644 --- a/packages/firebase_dynamic_links/firebase_dynamic_links/example/pubspec.yaml +++ b/packages/firebase_dynamic_links/firebase_dynamic_links/example/pubspec.yaml @@ -15,6 +15,8 @@ dependencies: url_launcher: ^6.1.0 dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_core: path: ../../../firebase_core/firebase_core firebase_core_platform_interface: diff --git a/packages/firebase_dynamic_links/firebase_dynamic_links_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_dynamic_links/firebase_dynamic_links_platform_interface/lib/src/method_channel/utils/exception.dart index d58916c919ce..c962121b1498 100644 --- a/packages/firebase_dynamic_links/firebase_dynamic_links_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_dynamic_links/firebase_dynamic_links_platform_interface/lib/src/method_channel/utils/exception.dart @@ -5,45 +5,15 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; + /// Catches a [PlatformException] and returns an [Exception]. /// /// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. Never convertPlatformException(Object exception, StackTrace stackTrace) { - if (exception is! Exception || exception is! PlatformException) { - Error.throwWithStackTrace(exception, stackTrace); - } - - Error.throwWithStackTrace( - platformExceptionToFirebaseException(exception, stackTrace), + convertPlatformExceptionToFirebaseException( + exception, stackTrace, - ); -} - -/// Converts a [PlatformException] into a [FirebaseException]. -/// -/// A [PlatformException] can only be converted to a [FirebaseException] if the -/// `details` of the exception exist. Firebase returns specific codes and messages -/// which can be converted into user friendly exceptions. -FirebaseException platformExceptionToFirebaseException( - PlatformException platformException, - StackTrace? stackTrace, -) { - Map? details = platformException.details != null - ? Map.from(platformException.details) - : null; - - String code = 'unknown'; - String message = platformException.message ?? ''; - - if (details != null) { - code = details['code'] ?? code; - message = details['message'] ?? message; - } - - return FirebaseException( plugin: 'firebase_dynamic_links', - code: code, - message: message, - stackTrace: stackTrace, ); } diff --git a/packages/firebase_dynamic_links/firebase_dynamic_links_platform_interface/pubspec.yaml b/packages/firebase_dynamic_links/firebase_dynamic_links_platform_interface/pubspec.yaml index 8162078fb97d..ae92743655ae 100644 --- a/packages/firebase_dynamic_links/firebase_dynamic_links_platform_interface/pubspec.yaml +++ b/packages/firebase_dynamic_links/firebase_dynamic_links_platform_interface/pubspec.yaml @@ -9,6 +9,7 @@ environment: flutter: ">=1.9.1+hotfix.5" dependencies: + _flutterfire_internals: ^1.0.0 firebase_core: ^1.10.3 flutter: sdk: flutter diff --git a/packages/firebase_in_app_messaging/firebase_in_app_messaging/example/pubspec.yaml b/packages/firebase_in_app_messaging/firebase_in_app_messaging/example/pubspec.yaml index 87e6798a953b..511e56cfbb5c 100644 --- a/packages/firebase_in_app_messaging/firebase_in_app_messaging/example/pubspec.yaml +++ b/packages/firebase_in_app_messaging/firebase_in_app_messaging/example/pubspec.yaml @@ -19,6 +19,8 @@ dependencies: sdk: flutter dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_core: path: ../../../firebase_core/firebase_core firebase_core_platform_interface: diff --git a/packages/firebase_in_app_messaging/firebase_in_app_messaging_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_in_app_messaging/firebase_in_app_messaging_platform_interface/lib/src/method_channel/utils/exception.dart index 6bcc3f8b0d53..c746430ca8a1 100644 --- a/packages/firebase_in_app_messaging/firebase_in_app_messaging_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_in_app_messaging/firebase_in_app_messaging_platform_interface/lib/src/method_channel/utils/exception.dart @@ -5,45 +5,15 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; + /// Catches a [PlatformException] and returns an [Exception]. /// /// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. Never convertPlatformException(Object exception, StackTrace stackTrace) { - if (exception is! Exception || exception is! PlatformException) { - Error.throwWithStackTrace(exception, stackTrace); - } - - Error.throwWithStackTrace( - platformExceptionToFirebaseException(exception, stackTrace), + convertPlatformExceptionToFirebaseException( + exception, stackTrace, - ); -} - -/// Converts a [PlatformException] into a [FirebaseException]. -/// -/// A [PlatformException] can only be converted to a [FirebaseException] if -/// the `details` of the exception exist. Firebase returns specific codes and -/// messages which can be converted into user friendly exceptions. -FirebaseException platformExceptionToFirebaseException( - PlatformException platformException, - StackTrace? stackTrace, -) { - Map? details = platformException.details != null - ? Map.from(platformException.details) - : null; - - String code = 'unknown'; - String? message = platformException.message; - - if (details != null) { - code = details['code'] ?? code; - message = details['message'] ?? message; - } - - return FirebaseException( plugin: 'firebase_in_app_messaging', - code: code, - message: message, - stackTrace: stackTrace, ); } diff --git a/packages/firebase_in_app_messaging/firebase_in_app_messaging_platform_interface/pubspec.yaml b/packages/firebase_in_app_messaging/firebase_in_app_messaging_platform_interface/pubspec.yaml index 00e3c4ba334c..1a5aae9b44c7 100644 --- a/packages/firebase_in_app_messaging/firebase_in_app_messaging_platform_interface/pubspec.yaml +++ b/packages/firebase_in_app_messaging/firebase_in_app_messaging_platform_interface/pubspec.yaml @@ -10,6 +10,7 @@ environment: flutter: ">=1.9.1+hotfix.5" dependencies: + _flutterfire_internals: ^1.0.0 firebase_core: ^1.10.0 flutter: sdk: flutter diff --git a/packages/firebase_messaging/firebase_messaging/example/pubspec.yaml b/packages/firebase_messaging/firebase_messaging/example/pubspec.yaml index 49d04cce2636..aa32f6c5d6e1 100644 --- a/packages/firebase_messaging/firebase_messaging/example/pubspec.yaml +++ b/packages/firebase_messaging/firebase_messaging/example/pubspec.yaml @@ -16,6 +16,8 @@ dependencies: http: ^0.13.0 dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_core: path: ../../../firebase_core/firebase_core firebase_core_platform_interface: diff --git a/packages/firebase_messaging/firebase_messaging_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_messaging/firebase_messaging_platform_interface/lib/src/method_channel/utils/exception.dart index 970d7c7b0280..30ddff68bb16 100644 --- a/packages/firebase_messaging/firebase_messaging_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_messaging/firebase_messaging_platform_interface/lib/src/method_channel/utils/exception.dart @@ -6,44 +6,15 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; -/// Catches a [PlatformException] and converts it into a [FirebaseException] if -/// it was intentionally caught on the native platform. -Never convertPlatformException(Object exception, StackTrace stackTrace) { - if (exception is! Exception || exception is! PlatformException) { - Error.throwWithStackTrace(exception, stackTrace); - } - - Error.throwWithStackTrace( - platformExceptionToFirebaseException(exception, stackTrace), - stackTrace, - ); -} +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; -/// Converts a [PlatformException] into a [FirebaseException]. +/// Catches a [PlatformException] and returns an [Exception]. /// -/// A [PlatformException] can only be converted to a [FirebaseException] if the -/// `details` of the exception exist. Firebase returns specific codes and messages -/// which can be converted into user friendly exceptions. -FirebaseException platformExceptionToFirebaseException( - PlatformException platformException, - StackTrace stackTrace, -) { - Map? details = platformException.details != null - ? Map.from(platformException.details) - : null; - - String code = 'unknown'; - String? message = platformException.message; - - if (details != null) { - code = details['code'] ?? code; - message = details['message'] ?? message; - } - - return FirebaseException( +/// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. +Never convertPlatformException(Object exception, StackTrace stackTrace) { + convertPlatformExceptionToFirebaseException( + exception, + stackTrace, plugin: 'firebase_messaging', - code: code, - message: message, - stackTrace: stackTrace, ); } diff --git a/packages/firebase_messaging/firebase_messaging_platform_interface/pubspec.yaml b/packages/firebase_messaging/firebase_messaging_platform_interface/pubspec.yaml index eb84c8e665a7..f7a87702803e 100644 --- a/packages/firebase_messaging/firebase_messaging_platform_interface/pubspec.yaml +++ b/packages/firebase_messaging/firebase_messaging_platform_interface/pubspec.yaml @@ -9,6 +9,7 @@ environment: flutter: ">=1.9.1+hotfix.5" dependencies: + _flutterfire_internals: ^1.0.0 firebase_core: ^1.10.0 flutter: sdk: flutter diff --git a/packages/firebase_messaging/firebase_messaging_web/lib/src/internals.dart b/packages/firebase_messaging/firebase_messaging_web/lib/src/internals.dart index c79287bfdaca..672d928401ca 100644 --- a/packages/firebase_messaging/firebase_messaging_web/lib/src/internals.dart +++ b/packages/firebase_messaging/firebase_messaging_web/lib/src/internals.dart @@ -1,9 +1,6 @@ -// ignore_for_file: require_trailing_commas -export 'package:firebase_core/src/internals.dart' hide guardWebExceptions; - import 'package:firebase_core/firebase_core.dart'; -// ignore: implementation_imports -import 'package:firebase_core/src/internals.dart' as internals; +import 'package:_flutterfire_internals/_flutterfire_internals.dart' + as internals; /// Will return a [FirebaseException] from a thrown web error. /// Any other errors will be propagated as normal. diff --git a/packages/firebase_messaging/firebase_messaging_web/pubspec.yaml b/packages/firebase_messaging/firebase_messaging_web/pubspec.yaml index 5ec8a0450561..c640e47fe5f9 100644 --- a/packages/firebase_messaging/firebase_messaging_web/pubspec.yaml +++ b/packages/firebase_messaging/firebase_messaging_web/pubspec.yaml @@ -9,6 +9,7 @@ environment: flutter: ">=1.12.13+hotfix.4" dependencies: + _flutterfire_internals: ^1.0.0 firebase_core: ^1.10.0 firebase_core_web: ^1.7.2 firebase_messaging_platform_interface: ^4.1.5 diff --git a/packages/firebase_ml_model_downloader/firebase_ml_model_downloader/example/pubspec.yaml b/packages/firebase_ml_model_downloader/firebase_ml_model_downloader/example/pubspec.yaml index 00a2ba79c78b..12bef8ce1ed8 100644 --- a/packages/firebase_ml_model_downloader/firebase_ml_model_downloader/example/pubspec.yaml +++ b/packages/firebase_ml_model_downloader/firebase_ml_model_downloader/example/pubspec.yaml @@ -31,6 +31,8 @@ dependencies: cupertino_icons: ^1.0.2 dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_core: path: ../../../firebase_core/firebase_core firebase_core_platform_interface: diff --git a/packages/firebase_performance/firebase_performance/example/pubspec.yaml b/packages/firebase_performance/firebase_performance/example/pubspec.yaml index 6d40615ac644..11dbae103954 100644 --- a/packages/firebase_performance/firebase_performance/example/pubspec.yaml +++ b/packages/firebase_performance/firebase_performance/example/pubspec.yaml @@ -16,6 +16,8 @@ dependencies: http: ^0.13.0 dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_core: path: ../../../firebase_core/firebase_core firebase_core_platform_interface: diff --git a/packages/firebase_performance/firebase_performance_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_performance/firebase_performance_platform_interface/lib/src/method_channel/utils/exception.dart index 5a2fcc387c03..b0a311a18415 100644 --- a/packages/firebase_performance/firebase_performance_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_performance/firebase_performance_platform_interface/lib/src/method_channel/utils/exception.dart @@ -5,44 +5,15 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; -/// Catches a [PlatformException] and converts it into a [FirebaseException] if -/// it was intentionally caught on the native platform. -Never convertPlatformException(Object exception, StackTrace stackTrace) { - if (exception is! Exception || exception is! PlatformException) { - Error.throwWithStackTrace(exception, stackTrace); - } - - Error.throwWithStackTrace( - platformExceptionToFirebaseException(exception, stackTrace), - stackTrace, - ); -} +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; -/// Converts a [PlatformException] into a [FirebaseException]. +/// Catches a [PlatformException] and returns an [Exception]. /// -/// A [PlatformException] can only be converted to a [FirebaseException] if the -/// `details` of the exception exist. Firebase returns specific codes and messages -/// which can be converted into user friendly exceptions. -FirebaseException platformExceptionToFirebaseException( - PlatformException platformException, - StackTrace? stackTrace, -) { - Map? details = platformException.details != null - ? Map.from(platformException.details) - : null; - - String code = 'unknown'; - String message = platformException.message ?? ''; - - if (details != null) { - code = details['code'] ?? code; - message = details['message'] ?? message; - } - - return FirebaseException( +/// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. +Never convertPlatformException(Object exception, StackTrace stackTrace) { + convertPlatformExceptionToFirebaseException( + exception, + stackTrace, plugin: 'firebase_performance', - code: code, - message: message, - stackTrace: stackTrace, ); } diff --git a/packages/firebase_performance/firebase_performance_platform_interface/pubspec.yaml b/packages/firebase_performance/firebase_performance_platform_interface/pubspec.yaml index a7c220f45b96..032cc0c876a6 100644 --- a/packages/firebase_performance/firebase_performance_platform_interface/pubspec.yaml +++ b/packages/firebase_performance/firebase_performance_platform_interface/pubspec.yaml @@ -8,6 +8,7 @@ environment: flutter: ">=1.17.0" dependencies: + _flutterfire_internals: ^1.0.0 firebase_core: ^1.10.0 flutter: sdk: flutter diff --git a/packages/firebase_performance/firebase_performance_web/lib/src/internals.dart b/packages/firebase_performance/firebase_performance_web/lib/src/internals.dart index 76a0ccb5e023..4d9c57243d4f 100644 --- a/packages/firebase_performance/firebase_performance_web/lib/src/internals.dart +++ b/packages/firebase_performance/firebase_performance_web/lib/src/internals.dart @@ -2,11 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -export 'package:firebase_core/src/internals.dart' hide guardWebExceptions; - import 'package:firebase_core/firebase_core.dart'; -// ignore: implementation_imports -import 'package:firebase_core/src/internals.dart' as internals; +import 'package:_flutterfire_internals/_flutterfire_internals.dart' + as internals; /// Will return a [FirebaseException] from a thrown web error. /// Any other errors will be propagated as normal. diff --git a/packages/firebase_performance/firebase_performance_web/pubspec.yaml b/packages/firebase_performance/firebase_performance_web/pubspec.yaml index 633eaae56082..0db93cce914e 100644 --- a/packages/firebase_performance/firebase_performance_web/pubspec.yaml +++ b/packages/firebase_performance/firebase_performance_web/pubspec.yaml @@ -8,6 +8,7 @@ environment: flutter: ">=1.20.0" dependencies: + _flutterfire_internals: ^1.0.0 firebase: ^9.0.1 firebase_core: ^1.10.0 firebase_core_web: ^1.7.2 diff --git a/packages/firebase_remote_config/firebase_remote_config/example/pubspec.yaml b/packages/firebase_remote_config/firebase_remote_config/example/pubspec.yaml index db8f1f9c2bfc..6c83c0747aba 100644 --- a/packages/firebase_remote_config/firebase_remote_config/example/pubspec.yaml +++ b/packages/firebase_remote_config/firebase_remote_config/example/pubspec.yaml @@ -17,6 +17,8 @@ dependencies: sdk: flutter dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_core: path: ../../../firebase_core/firebase_core firebase_core_platform_interface: diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart index d31524913911..4746da766b8c 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart @@ -2,44 +2,15 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; -/// Catches a [PlatformException] and converts it into a [FirebaseException] if -/// it was intentionally caught on the native platform. -Never convertPlatformException(Object exception, StackTrace stackTrace) { - if (exception is! Exception || exception is! PlatformException) { - Error.throwWithStackTrace(exception, stackTrace); - } - - Error.throwWithStackTrace( - platformExceptionToFirebaseException(exception, stackTrace), - stackTrace, - ); -} +import 'package:_flutterfire_internals/_flutterfire_internals.dart'; -/// Converts a [PlatformException] into a [FirebaseException]. +/// Catches a [PlatformException] and returns an [Exception]. /// -/// A [PlatformException] can only be converted to a [FirebaseException] if the -/// `details` of the exception exist. Firebase returns specific codes and messages -/// which can be converted into user friendly exceptions. -FirebaseException platformExceptionToFirebaseException( - PlatformException platformException, [ - StackTrace? stackTrace, -]) { - Map? details = platformException.details != null - ? Map.from(platformException.details) - : null; - - String code = 'unknown'; - String? message = platformException.message; - - if (details != null) { - code = details['code'] ?? code; - message = details['message'] ?? message; - } - - return FirebaseException( +/// If the [Exception] is a [PlatformException], a [FirebaseException] is returned. +Never convertPlatformException(Object exception, StackTrace stackTrace) { + convertPlatformExceptionToFirebaseException( + exception, + stackTrace, plugin: 'firebase_remote_config', - code: code, - message: message, - stackTrace: stackTrace, ); } diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/pubspec.yaml b/packages/firebase_remote_config/firebase_remote_config_platform_interface/pubspec.yaml index 5c2f53aea103..9bc63acbfee5 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/pubspec.yaml +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/pubspec.yaml @@ -11,6 +11,7 @@ environment: flutter: ">=1.9.1+hotfix.5" dependencies: + _flutterfire_internals: ^1.0.0 firebase_core: ^1.10.0 flutter: sdk: flutter diff --git a/packages/firebase_storage/firebase_storage/example/pubspec.yaml b/packages/firebase_storage/firebase_storage/example/pubspec.yaml index a0388c83b4a4..01224223865f 100755 --- a/packages/firebase_storage/firebase_storage/example/pubspec.yaml +++ b/packages/firebase_storage/firebase_storage/example/pubspec.yaml @@ -15,6 +15,8 @@ dependencies: image_picker_for_web: ^2.1.4 dependency_overrides: + _flutterfire_internals: + path: ../../../_flutterfire_internals firebase_core: path: ../../../firebase_core/firebase_core firebase_core_platform_interface: diff --git a/packages/firebase_storage/firebase_storage_web/lib/src/utils/errors.dart b/packages/firebase_storage/firebase_storage_web/lib/src/utils/errors.dart index 3274752f439a..8dc1a6e803b9 100644 --- a/packages/firebase_storage/firebase_storage_web/lib/src/utils/errors.dart +++ b/packages/firebase_storage/firebase_storage_web/lib/src/utils/errors.dart @@ -3,9 +3,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'package:_flutterfire_internals/_flutterfire_internals.dart' + as internals; import 'package:firebase_core/firebase_core.dart'; -// ignore: implementation_imports -import 'package:firebase_core/src/internals.dart' as internals; Map _errorCodeToMessage = { 'unauthorized': 'User is not authorized to perform the desired action.', diff --git a/packages/firebase_storage/firebase_storage_web/pubspec.yaml b/packages/firebase_storage/firebase_storage_web/pubspec.yaml index 2178d06f1093..9888aa0b10e6 100644 --- a/packages/firebase_storage/firebase_storage_web/pubspec.yaml +++ b/packages/firebase_storage/firebase_storage_web/pubspec.yaml @@ -9,6 +9,7 @@ environment: flutter: ">=1.20.0" dependencies: + _flutterfire_internals: ^1.0.0 async: ^2.5.0 firebase_core: ^1.10.0 firebase_core_web: ^1.7.2 diff --git a/tests/pubspec.yaml b/tests/pubspec.yaml index e691175cc66a..46cddd0e46d8 100644 --- a/tests/pubspec.yaml +++ b/tests/pubspec.yaml @@ -104,6 +104,8 @@ dependencies: http: ^0.13.4 dependency_overrides: + _flutterfire_internals: + path: ../packages/_flutterfire_internals cloud_firestore: path: ../packages/cloud_firestore/cloud_firestore cloud_firestore_platform_interface: