fix(android): Use componentStack as fallback for missing error stack traces#5965
Open
fix(android): Use componentStack as fallback for missing error stack traces#5965
Conversation
…traces When React render errors occur on Android with Hermes, the error may arrive at ErrorUtils.setGlobalHandler without a .stack property. However, React attaches a .componentStack with component locations and bundle offsets before the error reaches the handler. Use componentStack as a fallback for error.stack so that eventFromException can extract frames with source locations. 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. |
Contributor
antonis
commented
Apr 7, 2026
Contributor
Author
|
@sentry review |
Contributor
Author
|
@cursor review |
Sentry Build Distribution
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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 bc7535c. Configure here.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| // oxlint-disable-next-line typescript-eslint(no-unsafe-member-access) | ||
| if (error?.componentStack && (!error.stack || !hasStackFrames(error.stack))) { | ||
| // oxlint-disable-next-line typescript-eslint(no-unsafe-member-access) | ||
| error.stack = `${error.message || 'Error'}${error.componentStack}`; |
Collaborator
There was a problem hiding this comment.
shouldn't we add an extra space between the parameters, so Error is not clued to the componentStack message?
lucas-zimerman
approved these changes
Apr 8, 2026
Collaborator
lucas-zimerman
left a comment
There was a problem hiding this comment.
nit comment, other than that, LGTM!
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
When React render errors occur on Android with Hermes, the error may arrive at
ErrorUtils.setGlobalHandlerwithout a usable.stackproperty (empty or message-only). However, React'sReactFiberErrorDialogattaches a.componentStackto the error object before it reaches the handler. ThecomponentStackcontains component locations with bundle offsets that can be symbolicated by Sentry.This PR uses
componentStackas a fallback forerror.stackwhen the stack has no frames, so thateventFromExceptioncan extract frames with source locations.The fix handles both cases:
error.stackisundefined/emptyerror.stackis a message-only string with no frame lines (e.g."Error: Value is undefined, expected an Object")Note: The
componentStackis a React component tree (not a JS execution stack). After symbolication, it shows which component caused the error and its source location, but not the exact call chain within the component. This is the best information available on the JS side for this class of errors.💡 Motivation and Context
Fixes #5071
A user reported a fatal error
"Value is undefined, expected an Object"arriving in Sentry with no stacktrace, while Crashlytics captured the same error with a full component stack as aJavascriptException. The root cause is that some Hermes/JSI errors have no.stackproperty, but React attaches.componentStackwhich contains the same location information.See also: https://x.com/TheAnirudh/status/1954761591515476463
💚 How did you test it?
componentStackis used as fallback when.stackis missingcomponentStackis used when.stackis message-only (no frames).stackwith frames is not overriddendefaultStackParsercorrectly parses thecomponentStackformat includingaddress atprefixes📝 Checklist
sendDefaultPIIis enabled🔮 Next steps