From 50e54f0c19a6b668609401970dda86f0fcd6002c Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 06:01:55 +0000 Subject: [PATCH 01/22] Initial --- packages/firebase_crashlytics/CHANGELOG.md | 8 +++ packages/firebase_crashlytics/README.md | 52 ++++++++++++------- .../lib/src/firebase_crashlytics.dart | 17 ++++-- packages/firebase_crashlytics/pubspec.yaml | 2 +- 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/packages/firebase_crashlytics/CHANGELOG.md b/packages/firebase_crashlytics/CHANGELOG.md index 17da29918f4e..e7436d784c5e 100644 --- a/packages/firebase_crashlytics/CHANGELOG.md +++ b/packages/firebase_crashlytics/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.1.1 + +* Updated `README.md` to include both the breaking change from `0.1.0` and the newly added + `recordError` function in the setup section. +* Made the `_recordError` function safe for missing stack traces (`null`). +* Added the "Error reported to Crashlytics." print statement that was previously missing. +* Adjusted `README.md` formatting. + ## 0.1.0 * **Breaking Change** Renamed `onError` to `reportFlutterError`. diff --git a/packages/firebase_crashlytics/README.md b/packages/firebase_crashlytics/README.md index 1876b3f10ea1..96185fbfe2df 100644 --- a/packages/firebase_crashlytics/README.md +++ b/packages/firebase_crashlytics/README.md @@ -11,13 +11,13 @@ For Flutter plugins for other Firebase products, see [FlutterFire.md](https://gi ## Usage ### Import the firebase_crashlytics plugin -To use the firebase_crashlytics plugin, follow the [plugin installation instructions](https://pub.dartlang.org/packages/firebase_crashlytics#pub-pkg-tab-installing). +To use the `firebase_crashlytics` plugin, follow the [plugin installation instructions](https://pub.dartlang.org/packages/firebase_crashlytics#pub-pkg-tab-installing). ### Android integration -Enable the Google services by configuring the Gradle scripts as such. +Enable the Google services by configuring the Gradle scripts as such: -1. Add Fabric repository to the `[project]/android/build.gradle` file. +1. Add the Fabric repository to the `[project]/android/build.gradle` file. ``` repositories { google() @@ -29,7 +29,7 @@ repositories { } ``` -2. Add the classpaths to the `[project]/android/build.gradle` file. +2. Add the following classpaths to the `[project]/android/build.gradle` file. ```gradle dependencies { // Example existing classpath @@ -41,14 +41,14 @@ dependencies { } ``` -2. Add the apply plugins to the `[project]/android/app/build.gradle` file. +2. Apply the following plugins in the `[project]/android/app/build.gradle` file. ```gradle // ADD THIS AT THE BOTTOM apply plugin: 'io.fabric' apply plugin: 'com.google.gms.google-services' ``` -*Note:* If this section is not completed you will get an error like this: +*Note:* If this section is not completed, you will get an error like this: ``` java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process [package name]. @@ -56,18 +56,18 @@ Make sure to call FirebaseApp.initializeApp(Context) first. ``` *Note:* When you are debugging on Android, use a device or AVD with Google Play services. -Otherwise you will not be able to use Firebase Crashlytics. +Otherwise, you will not be able to use Firebase Crashlytics. ### iOS Integration -Add the Crashlytics run scripts +Add the Crashlytics run scripts: -1. From Xcode select Runner from the project navigation. -1. Select the Build Phases tab. -1. Click + Add a new build phase, and select New Run Script Phase. +1. From Xcode select `Runner` from the project navigation. +1. Select the `Build Phases` tab. +1. Click `+ Add a new build phase`, and select `New Run Script Phase`. 1. Add `${PODS_ROOT}/Fabric/run` to the `Type a script...` text box. -1. If on Xcode 10 Add your app's built Info.plist location to the Build Phase's Input Files field. -Eg: `$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)` +1. If you are using Xcode 10, add the location of `Info.plist`, built by your app, to the `Build Phase's Input Files` field. + E.g.: `$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)` ### Use the plugin @@ -85,20 +85,32 @@ void main() { // development. Crashlytics.instance.enableInDevMode = true; - // Pass all uncaught errors to Crashlytics. - FlutterError.onError = (FlutterErrorDetails details) { - Crashlytics.instance.onError(details); - }; + // Pass all uncaught errors from the framework to Crashlytics. + FlutterError.onError = Crashlytics.instance.recordFlutterError; + runApp(MyApp()); } ``` +Overriding the `FlutterError.onError` with `Crashlytics.instance.recordFlutterError` will automatically catch all +errors that are thrown from within the Flutter framework. +If you want to catch errors that occur in `runZoned`, +you can supply `Crashlytics.instance.recordError` to the `onError` parameter: +```dart +runZoned>(() async { + // ... + }, onError: Crashlytics.instance.recordError); +``` + ## Result If an error is caught, you should see the following messages in your logs: ``` -flutter: Error caught by Crashlytics plugin: -... +flutter: Flutter error caught by Crashlytics plugin: +// OR if you use recordError for runZoned: +flutter: Error caught by Crashlytics plugin : +// Exception and stack trace in debug mode +// OR if not in debug mode: flutter: Error reported to Crashlytics. ``` @@ -107,7 +119,7 @@ flutter: Error reported to Crashlytics. ## Example See the [example application](https://github.com/flutter/plugins/tree/master/packages/firebase_crashlytics/example) source -for a complete sample app using the Firebase Crashlytics. +for a complete sample app using `firebase_crashlytics`. ## Issues and feedback diff --git a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart index 1409c50f8bfa..4925cbe34020 100644 --- a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart +++ b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart @@ -193,14 +193,21 @@ class Crashlytics { } if (inDebugMode && !enableInDevMode) { - print(Trace.format(stack)); + // Need to print the exception to give context on what the exception is. + print(exception); + // Not using Trace.format here to stick to the default stack trace format + // that Flutter developers are used to seeing. + if (stack != null) print(stack); } else { - // Report error - final List stackTraceLines = + // Report error. The stack trace can be null. To avoid the following exception: + // Invalid argument(s): Cannot create a Trace from null. + // To avoid that exception, we can check for null and return an empty List. + final List stackTraceLines = stack == null ? null : Trace.format(stack).trimRight().split('\n'); final List> stackTraceElements = + stackTraceLines == null ? >[] : getStackTraceElements(stackTraceLines); - await channel + final String result = await channel .invokeMethod('Crashlytics#onError', { 'exception': "${exception.toString()}", 'context': '$context', @@ -208,6 +215,8 @@ class Crashlytics { 'logs': _logs.toList(), 'keys': _prepareKeys(), }); + // Print result. + print(result); } } } diff --git a/packages/firebase_crashlytics/pubspec.yaml b/packages/firebase_crashlytics/pubspec.yaml index d2d3d854c2a1..689209e6ee8e 100644 --- a/packages/firebase_crashlytics/pubspec.yaml +++ b/packages/firebase_crashlytics/pubspec.yaml @@ -2,7 +2,7 @@ name: firebase_crashlytics description: Flutter plugin for Firebase Crashlytics. It reports uncaught errors to the Firebase console. -version: 0.1.0 +version: 0.1.1 author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_crashlytics From 505fab17e51a1cc2140605a43b3437907cebb765 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 07:33:37 +0000 Subject: [PATCH 02/22] Second --- packages/firebase_crashlytics/README.md | 1 + .../FirebaseCrashlyticsPlugin.java | 10 ++++ .../ios/Classes/FirebaseCrashlyticsPlugin.m | 9 ++++ .../lib/src/firebase_crashlytics.dart | 47 ++++++++++++++----- .../test/firebase_crashlytics_test.dart | 8 ++++ 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/packages/firebase_crashlytics/README.md b/packages/firebase_crashlytics/README.md index 96185fbfe2df..9563b3023e8a 100644 --- a/packages/firebase_crashlytics/README.md +++ b/packages/firebase_crashlytics/README.md @@ -11,6 +11,7 @@ For Flutter plugins for other Firebase products, see [FlutterFire.md](https://gi ## Usage ### Import the firebase_crashlytics plugin + To use the `firebase_crashlytics` plugin, follow the [plugin installation instructions](https://pub.dartlang.org/packages/firebase_crashlytics#pub-pkg-tab-installing). ### Android integration diff --git a/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java b/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java index b3b04c6f37c3..40eb0060e1f9 100644 --- a/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java +++ b/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java @@ -70,6 +70,16 @@ public void onMethodCall(MethodCall call, Result result) { exception.setStackTrace(elements.toArray(new StackTraceElement[elements.size()])); Crashlytics.setString("exception", (String) call.argument("exception")); + + // Set context to show when the exception was thrown. + final String context = call.argument("context"); + if (context != null) Crashlytics.setString("context", "thrown " + context); + + // Log information + final String information = call.argument("information"); + if (information != null && !information.isEmpty()) + Crashlytics.log(information); + Crashlytics.logException(exception); result.success("Error reported to Crashlytics."); } else if (call.method.equals("Crashlytics#isDebuggable")) { diff --git a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m index f84a0abe17f0..4b3d5ae7f2b3 100644 --- a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m +++ b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m @@ -59,6 +59,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } } + // Add additional information from the Flutter framework to the exception reported in Crashlytics. + // CLS_LOG would also print to the log if it were called in debug mode, however, the + // "onError" method call only occurs in release mode, which is why this is fine. + // Otherwise, this should use CLSLog as explained here: https://support.crashlytics.com/knowledgebase/articles/92519-how-do-i-use-logging + NSString *information = call.arguments[@"information"]; + if ([information length] != 0) { + CLS_LOG(information); + } + // Report crash. NSArray *errorElements = call.arguments[@"stackTraceElements"]; NSMutableArray *frames = [NSMutableArray array]; diff --git a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart index 4925cbe34020..7bb10c242243 100644 --- a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart +++ b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart @@ -30,7 +30,8 @@ class Crashlytics { print('Flutter error caught by Crashlytics plugin:'); _recordError(details.exceptionAsString(), details.stack, - context: details.context); + context: details.context, + information: details.informationCollector == null ? null : details.informationCollector()); } /// Submits a report of a non-fatal error. @@ -165,6 +166,12 @@ class Crashlytics { 'line': lineNumber, }; + // The next section would throw an exception if there was no stop here. + if (lineParts.length < 3) { + elements.add(element); + continue; + } + if (lineParts[2].contains(".")) { final String className = lineParts[2].substring(0, lineParts[2].indexOf(".")).trim(); @@ -185,36 +192,54 @@ class Crashlytics { return elements; } + /// On top of the default exception components, [information] can be passed as well. + /// This allows the developer to get a better understanding of exceptions thrown + /// by the Flutter frame. [FlutterErrorDetails] often explain why an exception + /// occurred and give useful background information in [FlutterErrorDetails.informationCollector]. + /// Crashlytics will log this information in addition to the stack trace. + /// If [information] is `null` or empty, it will be ignored. Future _recordError(dynamic exception, StackTrace stack, - {dynamic context}) async { + {dynamic context, Iterable information}) async { bool inDebugMode = false; if (!enableInDevMode) { assert(inDebugMode = true); } + final String _information = + (information == null || information.isEmpty) ? '' : + (StringBuffer()..writeAll(information, '\n')).toString(); + if (inDebugMode && !enableInDevMode) { - // Need to print the exception to give context on what the exception is. + // If available, give context to the exception. + if (context != null) print('The following exception was thrown $context:'); + + // Need to print the exception to explain why the exception was thrown. print(exception); + + // Print information provided by the Flutter framework about the exception. + if (_information.isNotEmpty) print('\n$_information'); + // Not using Trace.format here to stick to the default stack trace format // that Flutter developers are used to seeing. - if (stack != null) print(stack); + if (stack != null) print('\n$stack'); } else { // Report error. The stack trace can be null. To avoid the following exception: // Invalid argument(s): Cannot create a Trace from null. - // To avoid that exception, we can check for null and return an empty List. - final List stackTraceLines = stack == null ? null : - Trace.format(stack).trimRight().split('\n'); - final List> stackTraceElements = - stackTraceLines == null ? >[] : - getStackTraceElements(stackTraceLines); + // To avoid that exception, we can check for null and provide an empty stack trace. + if (stack == null) stack = StackTrace.fromString(''); + + final List stackTraceLines = Trace.format(stack).trimRight().split('\n'); + final List> stackTraceElements = getStackTraceElements(stackTraceLines); final String result = await channel - .invokeMethod('Crashlytics#onError', { + .invokeMethod('Crashlytics#onError', { 'exception': "${exception.toString()}", 'context': '$context', + 'information': _information, 'stackTraceElements': stackTraceElements, 'logs': _logs.toList(), 'keys': _prepareKeys(), }); + // Print result. print(result); } diff --git a/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart b/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart index 5fef5850814d..baedc792a0d9 100644 --- a/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart +++ b/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart @@ -16,6 +16,8 @@ void main() { .setMockMethodCallHandler((MethodCall methodCall) async { log.add(methodCall); switch (methodCall.method) { + case 'Crashlytics#onError': + return 'Error reported to Crashlytics.'; case 'Crashlytics#isDebuggable': return true; case 'Crashlytics#setUserEmail': @@ -38,6 +40,11 @@ void main() { exception: 'foo exception', stack: StackTrace.current, library: 'foo library', + informationCollector: + () => [ + DiagnosticsNode.message('test message'), + DiagnosticsNode.message('second message'), + ], context: ErrorDescription('foo context'), ); crashlytics.enableInDevMode = true; @@ -50,6 +57,7 @@ void main() { expect(log[0].method, 'Crashlytics#onError'); expect(log[0].arguments['exception'], 'foo exception'); expect(log[0].arguments['context'], 'foo context'); + expect(log[0].arguments['information'], 'test message\nsecond message'); expect(log[0].arguments['logs'], isNotEmpty); expect(log[0].arguments['logs'], contains('foo')); expect(log[0].arguments['keys'][0]['key'], 'testBool'); From 810840097f504318c3f7908b2b4a04f1832f30db Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 07:37:19 +0000 Subject: [PATCH 03/22] minor --- packages/firebase_crashlytics/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_crashlytics/README.md b/packages/firebase_crashlytics/README.md index 9563b3023e8a..ecaa9f806b59 100644 --- a/packages/firebase_crashlytics/README.md +++ b/packages/firebase_crashlytics/README.md @@ -93,7 +93,7 @@ void main() { } ``` -Overriding the `FlutterError.onError` with `Crashlytics.instance.recordFlutterError` will automatically catch all +Overriding `FlutterError.onError` with `Crashlytics.instance.recordFlutterError` will automatically catch all errors that are thrown from within the Flutter framework. If you want to catch errors that occur in `runZoned`, you can supply `Crashlytics.instance.recordError` to the `onError` parameter: From 4b6f060dba16290892697d8587d3dcf6995a0f33 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 07:39:28 +0000 Subject: [PATCH 04/22] Changelog --- packages/firebase_crashlytics/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/firebase_crashlytics/CHANGELOG.md b/packages/firebase_crashlytics/CHANGELOG.md index e7436d784c5e..1478d7b220b4 100644 --- a/packages/firebase_crashlytics/CHANGELOG.md +++ b/packages/firebase_crashlytics/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.1.1 +* Added additional exception information from the Flutter framework to the reports. +* Reformatted debug printing of exceptions to be human-readable. * Updated `README.md` to include both the breaking change from `0.1.0` and the newly added `recordError` function in the setup section. * Made the `_recordError` function safe for missing stack traces (`null`). From 2f2f7f806901d04466d48f3b62f4308d1731ce09 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 07:41:46 +0000 Subject: [PATCH 05/22] minor --- packages/firebase_crashlytics/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_crashlytics/README.md b/packages/firebase_crashlytics/README.md index ecaa9f806b59..829f7cef9009 100644 --- a/packages/firebase_crashlytics/README.md +++ b/packages/firebase_crashlytics/README.md @@ -110,7 +110,7 @@ If an error is caught, you should see the following messages in your logs: flutter: Flutter error caught by Crashlytics plugin: // OR if you use recordError for runZoned: flutter: Error caught by Crashlytics plugin : -// Exception and stack trace in debug mode +// Exception, context, information and stack trace in debug mode // OR if not in debug mode: flutter: Error reported to Crashlytics. ``` From bc88da9adeb91d49310181178a2d8c380e79391e Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 07:42:16 +0000 Subject: [PATCH 06/22] comma --- packages/firebase_crashlytics/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_crashlytics/README.md b/packages/firebase_crashlytics/README.md index 829f7cef9009..9f3980a0d16b 100644 --- a/packages/firebase_crashlytics/README.md +++ b/packages/firebase_crashlytics/README.md @@ -110,7 +110,7 @@ If an error is caught, you should see the following messages in your logs: flutter: Flutter error caught by Crashlytics plugin: // OR if you use recordError for runZoned: flutter: Error caught by Crashlytics plugin : -// Exception, context, information and stack trace in debug mode +// Exception, context, information, and stack trace in debug mode // OR if not in debug mode: flutter: Error reported to Crashlytics. ``` From fec62db2c71e78a08490fe0adfd5714ec50e5acb Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 07:43:50 +0000 Subject: [PATCH 07/22] was --- .../ios/Classes/FirebaseCrashlyticsPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m index 4b3d5ae7f2b3..9d41de5f743c 100644 --- a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m +++ b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m @@ -60,7 +60,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } // Add additional information from the Flutter framework to the exception reported in Crashlytics. - // CLS_LOG would also print to the log if it were called in debug mode, however, the + // CLS_LOG would also print to the log if it was called in debug mode, however, the // "onError" method call only occurs in release mode, which is why this is fine. // Otherwise, this should use CLSLog as explained here: https://support.crashlytics.com/knowledgebase/articles/92519-how-do-i-use-logging NSString *information = call.arguments[@"information"]; From c0bae7bf55168b8a5394065f20479a395f3d20fe Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 07:46:51 +0000 Subject: [PATCH 08/22] minor --- packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart index 7bb10c242243..49b3b563c03b 100644 --- a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart +++ b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart @@ -166,7 +166,7 @@ class Crashlytics { 'line': lineNumber, }; - // The next section would throw an exception if there was no stop here. + // The next section would throw an exception in some cases if there was no stop here. if (lineParts.length < 3) { elements.add(element); continue; From 0116b260fa9e79c3a04ce0dcf9cb9d3b6ab68961 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 07:48:01 +0000 Subject: [PATCH 09/22] minor --- packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart index 49b3b563c03b..53beb709a3d7 100644 --- a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart +++ b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart @@ -194,7 +194,7 @@ class Crashlytics { /// On top of the default exception components, [information] can be passed as well. /// This allows the developer to get a better understanding of exceptions thrown - /// by the Flutter frame. [FlutterErrorDetails] often explain why an exception + /// by the Flutter framework. [FlutterErrorDetails] often explain why an exception /// occurred and give useful background information in [FlutterErrorDetails.informationCollector]. /// Crashlytics will log this information in addition to the stack trace. /// If [information] is `null` or empty, it will be ignored. From ec82c70e8471588b9e6177f420b856b2e0f122aa Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 07:51:35 +0000 Subject: [PATCH 10/22] minor --- .../firebase_crashlytics/lib/src/firebase_crashlytics.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart index 53beb709a3d7..5cf010071fd1 100644 --- a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart +++ b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart @@ -223,11 +223,12 @@ class Crashlytics { // that Flutter developers are used to seeing. if (stack != null) print('\n$stack'); } else { - // Report error. The stack trace can be null. To avoid the following exception: + // The stack trace can be null. To avoid the following exception: // Invalid argument(s): Cannot create a Trace from null. // To avoid that exception, we can check for null and provide an empty stack trace. if (stack == null) stack = StackTrace.fromString(''); + // Report error. final List stackTraceLines = Trace.format(stack).trimRight().split('\n'); final List> stackTraceElements = getStackTraceElements(stackTraceLines); final String result = await channel From 6ca5353121b83dd08976ddd0085afca916ba3699 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 08:12:26 +0000 Subject: [PATCH 11/22] CLSLog & format --- .../FirebaseCrashlyticsPlugin.java | 5 ++--- .../ios/Classes/FirebaseCrashlyticsPlugin.m | 8 +++---- .../lib/src/firebase_crashlytics.dart | 21 ++++++++++++------- .../test/firebase_crashlytics_test.dart | 9 ++++---- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java b/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java index 40eb0060e1f9..02862f6871a6 100644 --- a/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java +++ b/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java @@ -75,10 +75,9 @@ public void onMethodCall(MethodCall call, Result result) { final String context = call.argument("context"); if (context != null) Crashlytics.setString("context", "thrown " + context); - // Log information + // Log information. final String information = call.argument("information"); - if (information != null && !information.isEmpty()) - Crashlytics.log(information); + if (information != null && !information.isEmpty()) Crashlytics.log(information); Crashlytics.logException(exception); result.success("Error reported to Crashlytics."); diff --git a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m index 9d41de5f743c..c78a6892c420 100644 --- a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m +++ b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m @@ -60,12 +60,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } // Add additional information from the Flutter framework to the exception reported in Crashlytics. - // CLS_LOG would also print to the log if it was called in debug mode, however, the - // "onError" method call only occurs in release mode, which is why this is fine. - // Otherwise, this should use CLSLog as explained here: https://support.crashlytics.com/knowledgebase/articles/92519-how-do-i-use-logging + // Using CLSLog instead of CLS_LOG to try to avoid the automatic inclusion of the line number. + // It also ensures that the log is only written to Crashlytics and not also to the offline log + // as explained here: https://support.crashlytics.com/knowledgebase/articles/92519-how-do-i-use-logging NSString *information = call.arguments[@"information"]; if ([information length] != 0) { - CLS_LOG(information); + CLSLog(information); } // Report crash. diff --git a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart index 5cf010071fd1..73c6bda4e37c 100644 --- a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart +++ b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart @@ -31,7 +31,9 @@ class Crashlytics { _recordError(details.exceptionAsString(), details.stack, context: details.context, - information: details.informationCollector == null ? null : details.informationCollector()); + information: details.informationCollector == null + ? null + : details.informationCollector()); } /// Submits a report of a non-fatal error. @@ -205,13 +207,14 @@ class Crashlytics { assert(inDebugMode = true); } - final String _information = - (information == null || information.isEmpty) ? '' : - (StringBuffer()..writeAll(information, '\n')).toString(); + final String _information = (information == null || information.isEmpty) + ? '' + : (StringBuffer()..writeAll(information, '\n')).toString(); if (inDebugMode && !enableInDevMode) { // If available, give context to the exception. - if (context != null) print('The following exception was thrown $context:'); + if (context != null) + print('The following exception was thrown $context:'); // Need to print the exception to explain why the exception was thrown. print(exception); @@ -228,9 +231,11 @@ class Crashlytics { // To avoid that exception, we can check for null and provide an empty stack trace. if (stack == null) stack = StackTrace.fromString(''); - // Report error. - final List stackTraceLines = Trace.format(stack).trimRight().split('\n'); - final List> stackTraceElements = getStackTraceElements(stackTraceLines); + // Report error. + final List stackTraceLines = + Trace.format(stack).trimRight().split('\n'); + final List> stackTraceElements = + getStackTraceElements(stackTraceLines); final String result = await channel .invokeMethod('Crashlytics#onError', { 'exception': "${exception.toString()}", diff --git a/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart b/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart index baedc792a0d9..da6dafffb1e2 100644 --- a/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart +++ b/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart @@ -40,11 +40,10 @@ void main() { exception: 'foo exception', stack: StackTrace.current, library: 'foo library', - informationCollector: - () => [ - DiagnosticsNode.message('test message'), - DiagnosticsNode.message('second message'), - ], + informationCollector: () => [ + DiagnosticsNode.message('test message'), + DiagnosticsNode.message('second message'), + ], context: ErrorDescription('foo context'), ); crashlytics.enableInDevMode = true; From e936ba3077d644d2a32799b252c06d35628d2506 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 08:13:52 +0000 Subject: [PATCH 12/22] minor --- .../firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m index c78a6892c420..a61df97804fd 100644 --- a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m +++ b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m @@ -63,6 +63,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result // Using CLSLog instead of CLS_LOG to try to avoid the automatic inclusion of the line number. // It also ensures that the log is only written to Crashlytics and not also to the offline log // as explained here: https://support.crashlytics.com/knowledgebase/articles/92519-how-do-i-use-logging + // Although, that would only happen in debug mode, which this method call is never called in. NSString *information = call.arguments[@"information"]; if ([information length] != 0) { CLSLog(information); From f3aee1dff02bd086c1833d054ff42722e7a2fbea Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 08:17:12 +0000 Subject: [PATCH 13/22] minor --- .../ios/Classes/FirebaseCrashlyticsPlugin.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m index a61df97804fd..1d572cb686c1 100644 --- a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m +++ b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m @@ -62,7 +62,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result // Add additional information from the Flutter framework to the exception reported in Crashlytics. // Using CLSLog instead of CLS_LOG to try to avoid the automatic inclusion of the line number. // It also ensures that the log is only written to Crashlytics and not also to the offline log - // as explained here: https://support.crashlytics.com/knowledgebase/articles/92519-how-do-i-use-logging + // as explained here: + // https://support.crashlytics.com/knowledgebase/articles/92519-how-do-i-use-logging // Although, that would only happen in debug mode, which this method call is never called in. NSString *information = call.arguments[@"information"]; if ([information length] != 0) { From 09d85ec2cb4db2142926b736496bcaa8641c2409 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 08:22:54 +0000 Subject: [PATCH 14/22] format --- .../ios/Classes/FirebaseCrashlyticsPlugin.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m index 1d572cb686c1..ec981259afc8 100644 --- a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m +++ b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m @@ -59,10 +59,10 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } } - // Add additional information from the Flutter framework to the exception reported in Crashlytics. - // Using CLSLog instead of CLS_LOG to try to avoid the automatic inclusion of the line number. - // It also ensures that the log is only written to Crashlytics and not also to the offline log - // as explained here: + // Add additional information from the Flutter framework to the exception reported in + // Crashlytics. Using CLSLog instead of CLS_LOG to try to avoid the automatic inclusion of the + // line number. It also ensures that the log is only written to Crashlytics and not also to the + // offline log as explained here: // https://support.crashlytics.com/knowledgebase/articles/92519-how-do-i-use-logging // Although, that would only happen in debug mode, which this method call is never called in. NSString *information = call.arguments[@"information"]; From 663db2374b8f76a6658a59fa8321f6e3c4917b04 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 08:37:51 +0000 Subject: [PATCH 15/22] integration tests --- .../example/test_driver/crashlytics.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/firebase_crashlytics/example/test_driver/crashlytics.dart b/packages/firebase_crashlytics/example/test_driver/crashlytics.dart index 40bb08717189..dd62bdb7886a 100644 --- a/packages/firebase_crashlytics/example/test_driver/crashlytics.dart +++ b/packages/firebase_crashlytics/example/test_driver/crashlytics.dart @@ -28,6 +28,11 @@ void main() { FlutterErrorDetails( exception: 'testing', stack: StackTrace.fromString(''), + context: DiagnosticsNode.message('during testing'), + informationCollector: () => [ + DiagnosticsNode.message('testing'), + DiagnosticsNode.message('information'), + ] ), ); }); From c94a39bb8f1f27cd7bef0dfe790c2cd5464ae600 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 08:43:19 +0000 Subject: [PATCH 16/22] format --- .../example/test_driver/crashlytics.dart | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/firebase_crashlytics/example/test_driver/crashlytics.dart b/packages/firebase_crashlytics/example/test_driver/crashlytics.dart index dd62bdb7886a..687b4c07b35c 100644 --- a/packages/firebase_crashlytics/example/test_driver/crashlytics.dart +++ b/packages/firebase_crashlytics/example/test_driver/crashlytics.dart @@ -26,14 +26,13 @@ void main() { Crashlytics.instance.log('testing'); await crashlytics.recordFlutterError( FlutterErrorDetails( - exception: 'testing', - stack: StackTrace.fromString(''), - context: DiagnosticsNode.message('during testing'), - informationCollector: () => [ - DiagnosticsNode.message('testing'), - DiagnosticsNode.message('information'), - ] - ), + exception: 'testing', + stack: StackTrace.fromString(''), + context: DiagnosticsNode.message('during testing'), + informationCollector: () => [ + DiagnosticsNode.message('testing'), + DiagnosticsNode.message('information'), + ]) ); }); } From 93b3c9fa866edae83e63377390492f959475e1a1 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 08:48:39 +0000 Subject: [PATCH 17/22] format --- .../example/test_driver/crashlytics.dart | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/firebase_crashlytics/example/test_driver/crashlytics.dart b/packages/firebase_crashlytics/example/test_driver/crashlytics.dart index 687b4c07b35c..2cd26d0a1612 100644 --- a/packages/firebase_crashlytics/example/test_driver/crashlytics.dart +++ b/packages/firebase_crashlytics/example/test_driver/crashlytics.dart @@ -24,15 +24,13 @@ void main() { crashlytics.setDouble('testDouble', 42.0); crashlytics.setString('testString', 'bar'); Crashlytics.instance.log('testing'); - await crashlytics.recordFlutterError( - FlutterErrorDetails( - exception: 'testing', - stack: StackTrace.fromString(''), - context: DiagnosticsNode.message('during testing'), - informationCollector: () => [ - DiagnosticsNode.message('testing'), - DiagnosticsNode.message('information'), - ]) - ); + await crashlytics.recordFlutterError(FlutterErrorDetails( + exception: 'testing', + stack: StackTrace.fromString(''), + context: DiagnosticsNode.message('during testing'), + informationCollector: () => [ + DiagnosticsNode.message('testing'), + DiagnosticsNode.message('information'), + ])); }); } From 3bca8eb87bc3bb905709a24d94e7290166f10c18 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 09:03:08 +0000 Subject: [PATCH 18/22] changelog --- packages/firebase_crashlytics/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/firebase_crashlytics/CHANGELOG.md b/packages/firebase_crashlytics/CHANGELOG.md index 1478d7b220b4..dcc717e36ebe 100644 --- a/packages/firebase_crashlytics/CHANGELOG.md +++ b/packages/firebase_crashlytics/CHANGELOG.md @@ -7,10 +7,11 @@ * Made the `_recordError` function safe for missing stack traces (`null`). * Added the "Error reported to Crashlytics." print statement that was previously missing. * Adjusted `README.md` formatting. +* Fixed `recordFlutterError` method name in the `0.1.0` changelog entry. ## 0.1.0 -* **Breaking Change** Renamed `onError` to `reportFlutterError`. +* **Breaking Change** Renamed `onError` to `recordFlutterError`. * Added `recordError` method for errors caught using `runZoned`'s `onError`. ## 0.0.4+12 From 7c0a3bf650e7c09a18469a43bb6f59ef186041e5 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 19:02:35 +0000 Subject: [PATCH 19/22] implement suggestions --- packages/firebase_crashlytics/CHANGELOG.md | 8 ++++---- .../lib/src/firebase_crashlytics.dart | 14 +++++++------- packages/firebase_crashlytics/pubspec.yaml | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/firebase_crashlytics/CHANGELOG.md b/packages/firebase_crashlytics/CHANGELOG.md index dcc717e36ebe..5f4517d6f539 100644 --- a/packages/firebase_crashlytics/CHANGELOG.md +++ b/packages/firebase_crashlytics/CHANGELOG.md @@ -1,11 +1,11 @@ -## 0.1.1 +## 0.1.0+1 * Added additional exception information from the Flutter framework to the reports. -* Reformatted debug printing of exceptions to be human-readable. +* Refactored debug printing of exceptions to be human-readable. +* Passing `null` stack traces is now supported. +* Added the "Error reported to Crashlytics." print statement that was previously missing. * Updated `README.md` to include both the breaking change from `0.1.0` and the newly added `recordError` function in the setup section. -* Made the `_recordError` function safe for missing stack traces (`null`). -* Added the "Error reported to Crashlytics." print statement that was previously missing. * Adjusted `README.md` formatting. * Fixed `recordFlutterError` method name in the `0.1.0` changelog entry. diff --git a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart index 73c6bda4e37c..f9d7bce4fa0b 100644 --- a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart +++ b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart @@ -194,12 +194,12 @@ class Crashlytics { return elements; } - /// On top of the default exception components, [information] can be passed as well. - /// This allows the developer to get a better understanding of exceptions thrown - /// by the Flutter framework. [FlutterErrorDetails] often explain why an exception - /// occurred and give useful background information in [FlutterErrorDetails.informationCollector]. - /// Crashlytics will log this information in addition to the stack trace. - /// If [information] is `null` or empty, it will be ignored. + // On top of the default exception components, [information] can be passed as well. + // This allows the developer to get a better understanding of exceptions thrown + // by the Flutter framework. [FlutterErrorDetails] often explain why an exception + // occurred and give useful background information in [FlutterErrorDetails.informationCollector]. + // Crashlytics will log this information in addition to the stack trace. + // If [information] is `null` or empty, it will be ignored. Future _recordError(dynamic exception, StackTrace stack, {dynamic context, Iterable information}) async { bool inDebugMode = false; @@ -229,7 +229,7 @@ class Crashlytics { // The stack trace can be null. To avoid the following exception: // Invalid argument(s): Cannot create a Trace from null. // To avoid that exception, we can check for null and provide an empty stack trace. - if (stack == null) stack = StackTrace.fromString(''); + stack ??= StackTrace.fromString(''); // Report error. final List stackTraceLines = diff --git a/packages/firebase_crashlytics/pubspec.yaml b/packages/firebase_crashlytics/pubspec.yaml index 689209e6ee8e..4b4c063727e2 100644 --- a/packages/firebase_crashlytics/pubspec.yaml +++ b/packages/firebase_crashlytics/pubspec.yaml @@ -2,7 +2,7 @@ name: firebase_crashlytics description: Flutter plugin for Firebase Crashlytics. It reports uncaught errors to the Firebase console. -version: 0.1.1 +version: 0.1.0+1 author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_crashlytics From f1150ab97d5d8d5a217e81080207bad32dbdd6f3 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 19:23:54 +0000 Subject: [PATCH 20/22] Reason --- .../firebasecrashlytics/FirebaseCrashlyticsPlugin.java | 2 +- .../ios/Classes/FirebaseCrashlyticsPlugin.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java b/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java index 02862f6871a6..cd29c61d97c1 100644 --- a/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java +++ b/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java @@ -73,7 +73,7 @@ public void onMethodCall(MethodCall call, Result result) { // Set context to show when the exception was thrown. final String context = call.argument("context"); - if (context != null) Crashlytics.setString("context", "thrown " + context); + if (context != null) Crashlytics.setString("reason", "thrown " + context); // Log information. final String information = call.argument("information"); diff --git a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m index ec981259afc8..bf678c86c0fb 100644 --- a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m +++ b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m @@ -77,7 +77,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [frames addObject:[self generateFrame:errorElement]]; } [[Crashlytics sharedInstance] recordCustomExceptionName:call.arguments[@"exception"] - reason:call.arguments[@"context"] + reason:[NSString stringWithFormat:@"thrown %s", call.arguments[@"context"]] frameArray:frames]; result(@"Error reported to Crashlytics."); } else if ([@"Crashlytics#isDebuggable" isEqualToString:call.method]) { From 62c9117a4306ea99b7a68c868362c6132e0cc5da Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 19:32:24 +0000 Subject: [PATCH 21/22] format --- .../ios/Classes/FirebaseCrashlyticsPlugin.m | 8 +++++--- .../lib/src/firebase_crashlytics.dart | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m index bf678c86c0fb..d1354919e0f9 100644 --- a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m +++ b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m @@ -76,9 +76,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result for (NSDictionary *errorElement in errorElements) { [frames addObject:[self generateFrame:errorElement]]; } - [[Crashlytics sharedInstance] recordCustomExceptionName:call.arguments[@"exception"] - reason:[NSString stringWithFormat:@"thrown %s", call.arguments[@"context"]] - frameArray:frames]; + [[Crashlytics sharedInstance] + recordCustomExceptionName:call.arguments[@"exception"] + reason:[NSString + stringWithFormat:@"thrown %s", call.arguments[@"context"]] + frameArray:frames]; result(@"Error reported to Crashlytics."); } else if ([@"Crashlytics#isDebuggable" isEqualToString:call.method]) { result([NSNumber numberWithBool:[Crashlytics sharedInstance].debugMode]); diff --git a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart index f9d7bce4fa0b..23ed4ecea288 100644 --- a/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart +++ b/packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart @@ -236,6 +236,11 @@ class Crashlytics { Trace.format(stack).trimRight().split('\n'); final List> stackTraceElements = getStackTraceElements(stackTraceLines); + + // The context is a string that "should be in a form that will make sense in + // English when following the word 'thrown'" according to the documentation for + // [FlutterErrorDetails.context]. It is displayed to the user on Crashlytics + // as the "reason", which is forced by iOS, with the "thrown" prefix added. final String result = await channel .invokeMethod('Crashlytics#onError', { 'exception': "${exception.toString()}", From 618ea0deac8d50c88a585de0611c835e38ca0497 Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com> Date: Fri, 26 Jul 2019 19:36:20 +0000 Subject: [PATCH 22/22] minor --- .../firebasecrashlytics/FirebaseCrashlyticsPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java b/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java index cd29c61d97c1..0368738c939e 100644 --- a/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java +++ b/packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java @@ -71,7 +71,7 @@ public void onMethodCall(MethodCall call, Result result) { Crashlytics.setString("exception", (String) call.argument("exception")); - // Set context to show when the exception was thrown. + // Set a "reason" (to match iOS) to show where the exception was thrown. final String context = call.argument("context"); if (context != null) Crashlytics.setString("reason", "thrown " + context);