Skip to content
This repository was archived by the owner on Sep 14, 2020. It is now read-only.

Commit afdf343

Browse files
authored
fix(ios): Ensure duplicate native reports are discarded (#337)
If using `[BugsnagReactNative start]`, its possible that fatal JS reports are sent despite the discard block if they fail to be filtered before they are sent. This change moves the block to be called the first time Bugsnag is started, in either layer.
1 parent 79e84db commit afdf343

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
## TBD
5+
6+
### Bug fixes
7+
8+
* (iOS) Prevent delivering duplicate fatal JS crash reports when using enhanced
9+
native integration.
10+
411
## 2.16.0 (2019-04-04)
512

613
* (Android) Upgrade to bugsnag-android v4.13.0

cocoa/BugsnagReactNative.m

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ BSGBreadcrumbType BreadcrumbTypeFromString(NSString *type) {
9999
return frames;
100100
}
101101

102+
bool (^BSGReactNativeReportFilter)(NSDictionary *, BugsnagCrashReport *) = ^bool(NSDictionary *rawEventData,
103+
BugsnagCrashReport *_Nonnull report) {
104+
return !([report.errorClass hasPrefix:@"RCTFatalException"]
105+
&& [report.errorMessage hasPrefix:@"Unhandled JS Exception"]);
106+
};
107+
102108
@interface Bugsnag ()
103109
+ (id)notifier;
104110
+ (BOOL)bugsnagStarted;
@@ -121,10 +127,9 @@ + (void)start {
121127
}
122128

123129
+ (void)startWithAPIKey:(NSString *)APIKey {
124-
if (APIKey.length == 0)
125-
APIKey = [[NSBundle mainBundle] objectForInfoDictionaryKey:BSGInfoPlistKey];
126-
127-
[Bugsnag startBugsnagWithApiKey:APIKey];
130+
BugsnagConfiguration *config = [BugsnagConfiguration new];
131+
config.apiKey = APIKey;
132+
[self startWithConfiguration:config];
128133
}
129134

130135
+ (void)startWithConfiguration:(BugsnagConfiguration *)config {
@@ -136,6 +141,7 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
136141
// way to interact with the application should instead leverage startSession
137142
// manually.
138143
config.shouldAutoCaptureSessions = NO;
144+
[config addBeforeSendBlock:BSGReactNativeReportFilter];
139145
[Bugsnag startBugsnagWithConfiguration:config];
140146
}
141147

@@ -265,12 +271,6 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
265271
config.shouldAutoCaptureSessions = [RCTConvert BOOL:options[@"autoCaptureSessions"]];
266272
config.automaticallyCollectBreadcrumbs = [RCTConvert BOOL:options[@"automaticallyCollectBreadcrumbs"]];
267273

268-
[config addBeforeSendBlock:^bool(NSDictionary *_Nonnull rawEventData,
269-
BugsnagCrashReport *_Nonnull report) {
270-
return !([report.errorClass hasPrefix:@"RCTFatalException"]
271-
&& [report.errorMessage hasPrefix:@"Unhandled JS Exception"]);
272-
}];
273-
274274
if (notifyURLPath.length > 0) {
275275
[config setEndpointsForNotify:notifyURLPath
276276
sessions:sessionURLPath];
@@ -284,9 +284,12 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
284284
withValue:codeBundleId
285285
toTabWithName:@"app"];
286286
}
287-
if ([Bugsnag bugsnagStarted] && !config.autoNotify) {
288-
bsg_kscrash_setHandlingCrashTypes(BSG_KSCrashTypeUserReported);
289-
} else if (![Bugsnag bugsnagStarted]) {
287+
if ([Bugsnag bugsnagStarted]) {
288+
if (!config.autoNotify) {
289+
bsg_kscrash_setHandlingCrashTypes(BSG_KSCrashTypeUserReported);
290+
}
291+
} else {
292+
[config addBeforeSendBlock:BSGReactNativeReportFilter];
290293
[Bugsnag startBugsnagWithConfiguration:config];
291294
}
292295
[self setNotifierDetails:[RCTConvert NSString:options[@"version"]]];

0 commit comments

Comments
 (0)