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>
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. |
|
@sentry review |
|
@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}`; |
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
left a comment
There was a problem hiding this comment.
nit comment, other than that, LGTM!
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f5e7ddd. Configure here.
| */ | ||
| function hasStackFrames(stack: unknown): boolean { | ||
| return typeof stack === 'string' && stack.includes('\n'); | ||
| } |
There was a problem hiding this comment.
hasStackFrames newline check too permissive for edge cases
Low Severity
hasStackFrames uses stack.includes('\n') to detect frame lines, but a multi-line error message without any actual frames (e.g., "Error: something\nMore details") would also pass this check, preventing the componentStack fallback from being applied. Checking for a frame-like pattern (e.g., \n at or \n in ) would be more reliable.
Reviewed by Cursor Bugbot for commit f5e7ddd. Configure here.


📢 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