Skip to content

Unhandled JS Errors has duplication report with manual initialization the native SDKs #4649

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

Closed
jHolub opened this issue Mar 12, 2025 · 3 comments

Comments

@jHolub
Copy link

jHolub commented Mar 12, 2025

What React Native libraries do you use?

Hermes, React Native Navigation by Wix, React Native without Frameworks

Are you using sentry.io or on-premise?

sentry.io (SaS)

@sentry/react-native SDK Version

6.9.1

How does your development environment look like?

System:
OS: macOS 14.6.1
CPU: (12) arm64 Apple M3 Pro
Memory: 2.22 GB / 36.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.16.0
path: ~/.nvm/versions/node/v18.16.0/bin/node
Yarn:
version: 4.3.1
path: ~/.nvm/versions/node/v18.16.0/bin/yarn
npm:
version: 9.5.1
path: ~/.nvm/versions/node/v18.16.0/bin/npm
Watchman:
version: 2024.12.02.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.14.3
path: /Users/jiriholub/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.5
- iOS 17.5
- macOS 14.5
- tvOS 17.5
- visionOS 1.2
- watchOS 10.5
Android SDK: Not Found
IDEs:
Android Studio: 2024.1 AI-241.18034.62.2412.12266719
Xcode:
version: 15.4/15F31d
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.12
path: /usr/bin/javac
Ruby:
version: 3.1.6
path: /Users/jiriholub/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli":
installed: 15.1.3
wanted: 15.1.3
react: Not Found
react-native:
installed: 0.76.7
wanted: 0.76.7
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false

Sentry.init()

Sentry.init({
dsn: "...",
autoInitializeNativeSdk: false,
enabled: enableErrorReporting,
enableNative: enableErrorReporting,
environment: environment,
integrations: [
Sentry.reactNativeNavigationIntegration({
navigation: Navigation,
}),
],
});

in native part:

SentryAndroid.init(this) { options ->
  options.dsn = "..."
}

Steps to Reproduce

Make release build application and then create unhandled javascript error (e.g.: throw new Error()).
After restart application due to crash is reporting the error twice in sentry.io.

Expected Result

The error is reported only once after application crashing.

Actual Result

After restart application due to crash by unhandled javascript error is reporting the error twice in sentry.io.

@krystofwoldrich
Copy link
Member

Hi @jHolub,
thank you for the message.

Please add the following on Android side

// React native internally throws a JavascriptException.
// we want to ignore it on the native side to avoid sending it twice.
options.addIgnoredExceptionForType(JavascriptException.class);
and
// We don't want to send an event after startup that came from a Unhandled JS Exception of
// react native Because we sent it already before the app crashed.
if (nil != event.exceptions.firstObject.type &&
[event.exceptions.firstObject.type rangeOfString:@"Unhandled JS Exception"].location
!= NSNotFound) {
return nil;
}
on iOS side.

Let us know if this works for you.


PS: The reporting of unhandled JS errors will be handled out of the box when #3608 is released.

@krystofwoldrich krystofwoldrich moved this from Needs Discussion to Needs More Information in [DEPRECATED] Mobile SDKs Mar 12, 2025
@krystofwoldrich krystofwoldrich moved this from Needs More Information to Needs Validation in [DEPRECATED] Mobile SDKs Mar 12, 2025
@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 3 Mar 12, 2025
@jHolub
Copy link
Author

jHolub commented Mar 13, 2025

@krystofwoldrich Thank you for the response, but the version 6.9.1 already contains the above code.

The error only occurs when the package is setup manually. If the package is initialized only in the JS layer, everything is fine, but this method is not preferred by us.

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 13, 2025
@krystofwoldrich
Copy link
Member

Yes, the 6.9.1 contains the mentioned code, but it's only executed when using the automatic initialization of the native layers from JS.

If you manually initialize the Android and Cocoa SDKs, add the mentioned code to your init to avoid the duplicates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Archived in project
Development

No branches or pull requests

2 participants