diff --git a/Source/BugsnagCrashReport.m b/Source/BugsnagCrashReport.m index 77c512763..9b49319dc 100644 --- a/Source/BugsnagCrashReport.m +++ b/Source/BugsnagCrashReport.m @@ -384,7 +384,7 @@ - (void)addAttribute:(NSString *)attributeName toTabWithName:(NSString *)tabName { NSMutableDictionary *allMetadata = [self.metaData mutableCopy]; NSMutableDictionary *allTabData = - allMetadata[tabName] ?: [NSMutableDictionary new]; + [allMetadata[tabName] mutableCopy] ?: [NSMutableDictionary new]; if (value) { id cleanedValue = BSGSanitizeObject(value); if (!cleanedValue) { diff --git a/Source/BugsnagSink.m b/Source/BugsnagSink.m index f81920713..42902e3bc 100644 --- a/Source/BugsnagSink.m +++ b/Source/BugsnagSink.m @@ -26,6 +26,7 @@ #import "BugsnagSink.h" #import "Bugsnag.h" +#import "BugsnagLogger.h" #import "BugsnagCollections.h" #import "BugsnagNotifier.h" #import "BugsnagKeys.h" @@ -101,9 +102,13 @@ - (void)filterReports:(NSDictionary *)reports continue; BOOL shouldSend = YES; for (BugsnagBeforeSendBlock block in configuration.beforeSendBlocks) { - shouldSend = block(report, bugsnagReport); - if (!shouldSend) - break; + @try { + shouldSend = block(report, bugsnagReport); + if (!shouldSend) + break; + } @catch (NSException *exception) { + bsg_log_err(@"Error from beforeSend callback: %@", exception); + } } if (shouldSend) { [bugsnagReports addObject:bugsnagReport]; diff --git a/Tests/BugsnagCrashReportTests.m b/Tests/BugsnagCrashReportTests.m index e8eda5643..e3df0dcfb 100644 --- a/Tests/BugsnagCrashReportTests.m +++ b/Tests/BugsnagCrashReportTests.m @@ -460,4 +460,14 @@ - (void)testAppVersionOverride { XCTAssertEqualObjects(@"1.2.3", dictionary[@"app"][@"version"]); } +- (void)testReportAddAttr { + BugsnagCrashReport *report = [[BugsnagCrashReport alloc] initWithKSReport:@{@"user.metaData": @{@"user": @{@"id": @"user id"}}}]; + [report addAttribute:@"foo" withValue:@"bar" toTabWithName:@"user"]; +} + +- (void)testReportAddMetadata { + BugsnagCrashReport *report = [[BugsnagCrashReport alloc] initWithKSReport:@{@"user.metaData": @{@"user": @{@"id": @"user id"}}}]; + [report addMetadata:@{@"foo": @"bar"} toTabWithName:@"user"]; +} + @end