Skip to content

fix(core): Always return a string from _enhanceErrorWithSentryInfo - #26349

Merged
msonnb merged 2 commits into
getsentry:developfrom
bardrop:fix/enhance-error-message-string
Nov 13, 2026
Merged

msonnb merged 2 commits into
getsentry:developfrom
bardrop:fix/enhance-error-message-string

Conversation

@bardrop

@bardrop bardrop commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Why: Error.message is typed as a string, but code can assign anything to it. A number, object or function then ended up as exception.value, and an event processor that calls a string method on it (here DropReactControlFlowErrors in @sentry/nextjs) threw, so the event was dropped before beforeSend. As suggested in the issue, this makes _enhanceErrorWithSentryInfo always return a string instead of guarding each processor.

Primitives go through String(), objects through the existing stringify (JSON), with stringifyValue as the fallback for functions and circular objects ([Function: name], [object Object]). null/undefined become '', which keeps them falsy, so the browser 'No error message' path is unchanged.

How to review: packages/core/src/utils/eventbuilder.ts, then the new exceptionFromError cases in the test file (all fail on develop).

Unsure about: JSON for object messages. {"code":42} reads better than [object Object], but tell me if you'd rather keep it shorter.

Closes #26329

An Error whose `message` is not a string (a number, an object, a function)
used to end up as a non-string `exception.value`. Event processors that call
string methods on it then threw, and the event was dropped, e.g.
`DropReactControlFlowErrors` in @sentry/nextjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Other objects go through stringifyValue, so an Error, Map or DOM Event
as the message no longer becomes '{}' or '{"isTrusted":true}'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@msonnb
msonnb self-requested a review November 13, 2026 10:01
@msonnb
msonnb marked this pull request as ready for review November 13, 2026 10:01
@msonnb
msonnb requested a review from a team November 13, 2026 10:01

@msonnb msonnb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thank you!

@msonnb
msonnb merged commit cb9e84c into getsentry:develop Nov 13, 2026
387 checks passed
msonnb added a commit that referenced this pull request Nov 13, 2026
This PR adds the external contributor to the CHANGELOG.md file, so that
they are credited for their contribution. See #26349

Co-authored-by: msonnb <26038247+msonnb@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@sentry/nextjs: an Error whose message is not a string is dropped by DropReactControlFlowErrors ("includes is not a function")

2 participants