diff --git a/docs/crashlytics/_customize-crash-reports.md b/docs/crashlytics/_customize-crash-reports.md index db45ccec04c5..35d0daef5efc 100644 --- a/docs/crashlytics/_customize-crash-reports.md +++ b/docs/crashlytics/_customize-crash-reports.md @@ -97,7 +97,7 @@ event is reported or when the app restarts. Note: {{crashlytics}} only stores the most recent eight recorded non-fatal exceptions. If your app throws more than eight, older exceptions are lost. This count is reset each time a fatal exception is thrown, since this causes a report -to be sent to {{crashlytics}}. +to be sent to {{crashlytics}}. Use the `recordError` method to record non-fatal exceptions in your app's catch blocks. For example: @@ -110,6 +110,18 @@ await FirebaseCrashlytics.instance.recordError( ); ``` +You may also wish to log further information about the error which is possible +using the `information` property: + +```dart +await FirebaseCrashlytics.instance.recordError( + error, + stackTrace, + reason: 'a non-fatal error', + information: ['further diagnostic information about the error', 'version 2.0'], +); +``` + Warning: If you want to include a unique value (for example, a user ID or a timestamp) in your exception message, use a [custom key](#add-keys) instead of adding the value directly in the exception message. Adding values directly can diff --git a/packages/firebase_crashlytics/firebase_crashlytics/lib/firebase_crashlytics.dart b/packages/firebase_crashlytics/firebase_crashlytics/lib/firebase_crashlytics.dart index e76f92fa52e1..9bab1a9bc7cb 100644 --- a/packages/firebase_crashlytics/firebase_crashlytics/lib/firebase_crashlytics.dart +++ b/packages/firebase_crashlytics/firebase_crashlytics/lib/firebase_crashlytics.dart @@ -6,7 +6,7 @@ library firebase_crashlytics; import 'package:flutter/foundation.dart' - show kDebugMode, FlutterErrorDetails, FlutterError, DiagnosticsNode; + show kDebugMode, FlutterErrorDetails, FlutterError; import 'package:firebase_crashlytics_platform_interface/firebase_crashlytics_platform_interface.dart'; import 'package:firebase_core/firebase_core.dart'; diff --git a/packages/firebase_crashlytics/firebase_crashlytics/lib/src/firebase_crashlytics.dart b/packages/firebase_crashlytics/firebase_crashlytics/lib/src/firebase_crashlytics.dart index 51252caebcac..073f79664bc5 100644 --- a/packages/firebase_crashlytics/firebase_crashlytics/lib/src/firebase_crashlytics.dart +++ b/packages/firebase_crashlytics/firebase_crashlytics/lib/src/firebase_crashlytics.dart @@ -79,7 +79,7 @@ class FirebaseCrashlytics extends FirebasePluginPlatform { /// Submits a Crashlytics report of a caught error. Future recordError(dynamic exception, StackTrace? stack, {dynamic reason, - Iterable information = const [], + Iterable information = const [], bool? printDetails, bool fatal = false}) async { // Use the debug flag if printDetails is not provided @@ -139,13 +139,13 @@ class FirebaseCrashlytics extends FirebasePluginPlatform { {bool fatal = false}) { FlutterError.presentError(flutterErrorDetails); + final information = flutterErrorDetails.informationCollector?.call() ?? []; + return recordError( flutterErrorDetails.exceptionAsString(), flutterErrorDetails.stack, reason: flutterErrorDetails.context, - information: flutterErrorDetails.informationCollector == null - ? [] - : flutterErrorDetails.informationCollector!(), + information: information, printDetails: false, fatal: fatal, );