Skip to content

Commit b56950f

Browse files
committed
Add fix and tests for immutable metadata tabs
1 parent da9669c commit b56950f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Source/BugsnagCrashReport.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ - (void)addAttribute:(NSString *)attributeName
384384
toTabWithName:(NSString *)tabName {
385385
NSMutableDictionary *allMetadata = [self.metaData mutableCopy];
386386
NSMutableDictionary *allTabData =
387-
allMetadata[tabName] ?: [NSMutableDictionary new];
387+
[allMetadata[tabName] mutableCopy] ?: [NSMutableDictionary new];
388388
if (value) {
389389
id cleanedValue = BSGSanitizeObject(value);
390390
if (!cleanedValue) {

Source/BugsnagSink.m

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#import "BugsnagSink.h"
2828
#import "Bugsnag.h"
29+
#import "BugsnagLogger.h"
2930
#import "BugsnagCollections.h"
3031
#import "BugsnagNotifier.h"
3132
#import "BugsnagKeys.h"
@@ -101,9 +102,13 @@ - (void)filterReports:(NSDictionary <NSString *, NSDictionary *> *)reports
101102
continue;
102103
BOOL shouldSend = YES;
103104
for (BugsnagBeforeSendBlock block in configuration.beforeSendBlocks) {
104-
shouldSend = block(report, bugsnagReport);
105-
if (!shouldSend)
106-
break;
105+
@try {
106+
shouldSend = block(report, bugsnagReport);
107+
if (!shouldSend)
108+
break;
109+
} @catch (NSException *exception) {
110+
bsg_log_err(@"Error from beforeSend callback: %@", exception);
111+
}
107112
}
108113
if (shouldSend) {
109114
[bugsnagReports addObject:bugsnagReport];

Tests/BugsnagCrashReportTests.m

+10
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,14 @@ - (void)testAppVersionOverride {
460460
XCTAssertEqualObjects(@"1.2.3", dictionary[@"app"][@"version"]);
461461
}
462462

463+
- (void)testReportAddAttr {
464+
BugsnagCrashReport *report = [[BugsnagCrashReport alloc] initWithKSReport:@{@"user.metaData": @{@"user": @{@"id": @"user id"}}}];
465+
[report addAttribute:@"foo" withValue:@"bar" toTabWithName:@"user"];
466+
}
467+
468+
- (void)testReportAddMetadata {
469+
BugsnagCrashReport *report = [[BugsnagCrashReport alloc] initWithKSReport:@{@"user.metaData": @{@"user": @{@"id": @"user id"}}}];
470+
[report addMetadata:@{@"foo": @"bar"} toTabWithName:@"user"];
471+
}
472+
463473
@end

0 commit comments

Comments
 (0)