Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discard duplicate JS exceptions in iOS New Architecture #2148

Merged
merged 3 commits into from
May 30, 2024

Conversation

yousif-bugsnag
Copy link
Contributor

Goal

In the Old Architecture React Native raises an Objective-C RCTFatalException when an unhandled JS exception occurs. These are discarded in the native notifier because BugSnag's JS layer also catches these JS exceptions.

However in 0.73+, with New Architecture enabled, these exceptions are caught and rethrown as a cpp exception, so the discard pattern no longer applies and a duplicate native event is reported.

This PR adds an additional onSendError block (when the New Architecture is enabled) to also discard these new exception types

Design

Because this new exception type facebook::jsi::JSError is also thrown for any exceptions that occur in Turbo Module methods, we're not able to discard unhandled JS exceptions using a discardClasses pattern.

Instead an onSendError callback is used to discard based on the error message. For unhandled JS exceptions the error message is always prepended with Exception in HostFunction: Unhandled JS Exception

Changeset

Added a new onSendError block to the native config in BugsnagReactNativePlugin.m if the New Architecture is enabled.

The iOS New Architecture tests for 0.73 have been reinstated - as part of this all scenarios that throw native exceptions have been split into separate tests for old arch and new arch to account for the new exception handling behaviour in iOS Turbo Modules

Testing

Covered by a full CI run

Copy link

github-actions bot commented May 29, 2024

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 43.80 kB 13.43 kB
After 43.80 kB 13.43 kB
± No change No change

code coverage diff

<temporarily disabled>

Generated by 🚫 dangerJS against 529ed20

Copy link
Member

@gingerbenw gingerbenw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - can I also say the PR description is great, loads of detail! 👍🏻

@yousif-bugsnag yousif-bugsnag force-pushed the PLAT-12064/ios-tm-discard-duplicates branch from 00ac246 to 529ed20 Compare May 30, 2024 08:54
@yousif-bugsnag yousif-bugsnag merged commit 80f95b4 into next May 30, 2024
57 checks passed
@yousif-bugsnag yousif-bugsnag deleted the PLAT-12064/ios-tm-discard-duplicates branch May 30, 2024 09:56
@yousif-bugsnag yousif-bugsnag mentioned this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants