diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m index f76854825..c8c282a7b 100644 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -540,26 +540,38 @@ - (void)logEvent:(CDVInvokedUrlCommand *)command { - (void)logError:(CDVInvokedUrlCommand *)command { [self.commandDelegate runInBackground:^{ NSString* errorMessage = [command.arguments objectAtIndex:0]; - NSMutableDictionary* userInfo = [[NSMutableDictionary alloc] init]; + CDVCommandStatus status = CDVCommandStatus_OK; - @try { // We can optionally be passed a stack trace from stackTrace.js which we'll put in userInfo. if ([command.arguments count] > 1) { - NSArray *stack = [command.arguments objectAtIndex:1]; - int lineNum = 1; - for (NSDictionary *entry in stack) { - NSString *key = [NSString stringWithFormat:@"Stack_line_%02d", lineNum++]; - userInfo[key] = entry[@"source"]; + NSArray* stackFrames = [command.arguments objectAtIndex:1]; + + NSString* message = errorMessage; + NSString* name = @"Uncaught Javascript exception"; + NSMutableArray *customFrames = [[NSMutableArray alloc] init]; + + for (NSDictionary* stackFrame in stackFrames) { + CLSStackFrame *customFrame = [CLSStackFrame stackFrame]; + [customFrame setSymbol:stackFrame[@"functionName"]]; + [customFrame setFileName:stackFrame[@"fileName"]]; + [customFrame setLibrary:stackFrame[@"source"]]; + [customFrame setOffset:(uint64_t) [stackFrame[@"columnNumber"] intValue]]; + [customFrame setLineNumber:(uint32_t) [stackFrame[@"lineNumber"] intValue]]; + [customFrames addObject:customFrame]; } + [[Crashlytics sharedInstance] recordCustomExceptionName:name reason:message frameArray:customFrames]; + }else{ + //TODO detect and handle non-stack userInfo and pass to recordError + NSMutableDictionary* userInfo = [[NSMutableDictionary alloc] init]; + NSError *error = [NSError errorWithDomain:errorMessage code:0 userInfo:userInfo]; + [CrashlyticsKit recordError:error]; } } @catch (NSException *exception) { CLSNSLog(@"Exception in logError: %@, original error: %@", exception.description, errorMessage); status = CDVCommandStatus_ERROR; } - - NSError *error = [NSError errorWithDomain:errorMessage code:0 userInfo:userInfo]; - [CrashlyticsKit recordError:error]; + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:status]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }];