Skip to content

Commit

Permalink
Merge pull request #1549 from bugsnag/yousif/PLAT-10016/persist-origi…
Browse files Browse the repository at this point in the history
…nal-unhandled-events
  • Loading branch information
yousif-bugsnag authored Apr 19, 2023
2 parents fbe4d51 + d02c20f commit 23bb82c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Bugsnag/Client/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ - (void)notifyInternal:(BugsnagEvent *_Nonnull)event

event.usage = BSGTelemetryCreateUsage(self.configuration);

if (event.unhandled) {
if (event.handledState.originalUnhandledValue) {
// Unhandled Javscript exceptions from React Native result in the app being terminated shortly after the
// call to notifyInternal, so the event needs to be persisted to disk for sending in the next session.
// The fatal "RCTFatalException" / "Unhandled JS Exception" is explicitly ignored by
Expand Down
1 change: 1 addition & 0 deletions Bugsnag/Payload/BugsnagHandledState.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ BUGSNAG_EXTERN

@property(nonatomic) BOOL unhandled;
@property(nonatomic) BOOL unhandledOverridden;
@property(nonatomic, readonly) BOOL originalUnhandledValue;
@property(nonatomic, readonly) SeverityReasonType severityReasonType;
@property(nonatomic, readonly) BSGSeverity originalSeverity;
@property(nonatomic) BSGSeverity currentSeverity;
Expand Down
4 changes: 4 additions & 0 deletions Bugsnag/Payload/BugsnagHandledState.m
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,8 @@ - (NSDictionary *)toJson {
return dict;
}

- (BOOL)originalUnhandledValue {
return self.unhandledOverridden ? !self.unhandled : self.unhandled;
}

@end
18 changes: 18 additions & 0 deletions Tests/BugsnagTests/BugsnagHandledStateTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,22 @@ - (void)testPromiseRejection {
XCTAssertNil(state.attrValue);
}

- (void)testOriginalUnhandled {
BugsnagHandledState *unhandledState =
[BugsnagHandledState handledStateWithSeverityReason:PromiseRejection];
XCTAssertTrue(unhandledState.originalUnhandledValue);

unhandledState.unhandledOverridden = YES;
XCTAssertFalse(unhandledState.originalUnhandledValue);

BugsnagHandledState *handledState =
[BugsnagHandledState handledStateWithSeverityReason:HandledError
severity:BSGSeverityWarning
attrValue:@"Test"];
XCTAssertFalse(handledState.originalUnhandledValue);

handledState.unhandledOverridden = YES;
XCTAssertTrue(handledState.originalUnhandledValue);
}

@end

0 comments on commit 23bb82c

Please sign in to comment.