fix(android): Recover missing JS stack traces from native JavascriptException#5964
Closed
fix(android): Recover missing JS stack traces from native JavascriptException#5964
Conversation
…xception On Android with Hermes, React render errors can arrive at the JS-side ErrorUtils.setGlobalHandler without a .stack property. The same error is captured by RN's native layer as a JavascriptException which contains the full JS stack trace string. Previously, JavascriptException was fully ignored via addIgnoredExceptionForType, discarding the stack information. Now we intercept it in beforeSend, cache the stack trace, and expose it to JS via a sync bridge method. A new NativeStackRecovery integration fetches and parses the cached stack when an event has no frames. Fixes #5071 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
🤖 This preview updates automatically when you update the PR. |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit efac955. Configure here.
Sentry Build Distribution
|
Contributor
Author
|
Superseded by a simpler approach — using React's componentStack as a fallback instead of bridging the native JavascriptException stack. See new PR. |
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📢 Type of change
📜 Description
On Android with Hermes, React render errors can arrive at the JS-side
ErrorUtils.setGlobalHandlerwithout a.stackproperty. The same error is captured by React Native's native layer as aJavascriptExceptionwhich contains the full JS stack trace string (with component names and bundle offsets).Previously,
JavascriptExceptionwas fully ignored viaaddIgnoredExceptionForType, discarding the stack information entirely. This PR:JavascriptExceptioninbeforeSendinstead of ignoring it — caches the stack trace string, then drops the event (same dedup behavior)fetchCachedJavascriptExceptionStack)NativeStackRecoveryintegration that fetches and parses the cached stack when an event has no framesThe cache uses
AtomicReferencewith a 5-second TTL and single-consumption (getAndClear) semantics.💡 Motivation and Context
Fixes #5071
A user reported a fatal error
"Value is undefined, expected an Object"arriving in Sentry with zero stacktrace frames, while Crashlytics captured the same error with a full stack as aJavascriptException. The root cause is that React's error handling transforms render errors before they reach the JS global error handler, stripping the.stackproperty. The nativeJavascriptExceptionretains the original stack but was being discarded.See also: https://x.com/TheAnirudh/status/1954761591515476463
💚 How did you test it?
NativeStackRecoveryintegration (all branches covered)beforeSendJavascriptException handlingNativeStackRecoveryruns beforeRewriteFramesdefaultStackParsercorrectly parsesJavascriptException.getMessage()format includingaddress atprefixes📝 Checklist
sendDefaultPIIis enabled🔮 Next steps