From b40e3bb87b8815e4c217458756145174f370cf2b Mon Sep 17 00:00:00 2001 From: Josh Burton Date: Tue, 30 Jul 2019 14:56:43 +1200 Subject: [PATCH] [firebase-crashlytics] Fixes exception when trying to format crash reason when the crash has no context (#1931) --- packages/firebase_crashlytics/CHANGELOG.md | 4 ++++ .../ios/Classes/FirebaseCrashlyticsPlugin.m | 15 ++++++++++----- packages/firebase_crashlytics/pubspec.yaml | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/firebase_crashlytics/CHANGELOG.md b/packages/firebase_crashlytics/CHANGELOG.md index 5f4517d6f539..6b85c00fea17 100644 --- a/packages/firebase_crashlytics/CHANGELOG.md +++ b/packages/firebase_crashlytics/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.0+2 + +* [iOS] Fixes crash when trying to report a crash without any context + ## 0.1.0+1 * Added additional exception information from the Flutter framework to the reports. diff --git a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m index d1354919e0f9..862072f756f0 100644 --- a/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m +++ b/packages/firebase_crashlytics/ios/Classes/FirebaseCrashlyticsPlugin.m @@ -76,11 +76,16 @@ - (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]; + + NSString *context = call.arguments[@"context"]; + NSString *reason; + if (context != nil) { + reason = [NSString stringWithFormat:@"thrown %@", context]; + } + + [[Crashlytics sharedInstance] recordCustomExceptionName:call.arguments[@"exception"] + reason:reason + 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/pubspec.yaml b/packages/firebase_crashlytics/pubspec.yaml index 4b4c063727e2..5b1542554213 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+1 +version: 0.1.0+2 author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_crashlytics