Skip to content

Stop double-reporting unhandled promise rejections - #9628

Merged
OfekShilon merged 1 commit into
compiler-explorer:mainfrom
OfekShilon:claude/fix-sentry-COMPILER-EXPLORER-EHY
Nov 21, 2026
Merged

OfekShilon merged 1 commit into
compiler-explorer:mainfrom
OfekShilon:claude/fix-sentry-COMPILER-EXPLORER-EHY

Conversation

@OfekShilon

Copy link
Copy Markdown
Member

Fixes Sentry COMPILER-EXPLORER-EHY ("Error: Non-Error rejection: {}", 351 events in 30 days) and its sibling COMPILER-EXPLORER-EJ9 ("Non-Error rejection: undefined", 5.8k events in total).

Root cause

SetupSentry() adds its own unhandledrejection listener, but Sentry's default GlobalHandlers integration already captures every unhandled rejection (onunhandledrejection: true; we don't override integrations). That means every rejection gets reported twice:

  • Sentry's built-in copy handles cross-realm Errors properly via isError, and turns Event/CustomEvent rejections into Event 'CustomEvent' (type=…) captured as promise rejection. It also puts the type, target and detail into extra.__serialized__.
  • CE's copy checks reason instanceof Error, and that check fails for Errors created in another realm, such as Safari extension content scripts. It then runs JSON.stringify(reason) on them, and since Error properties are non-enumerable the result is {}.

Evidence from Sentry:

  • EHY's events line up timestamp for timestamp with properly titled built-in events in other issues. One example is COMPILER-EXPLORER-DJ2: Invalid call to runtime.sendMessage(). Tab not found. from a Safari extension, with mechanism auto.browser.global_handlers.onunhandledrejection.
  • The "Request timeout …" variants of EHY match their built-in twins count for count.
  • The title of the issue Extract diagnostic info from Safari CustomEvent rejections #8173 set out to fix (DXM, Event 'CustomEvent' (type=unhandledrejection) captured as promise rejection) is itself the built-in handler's format. So the built-in handler was already reporting those events.

Fix

Remove the custom listener, together with the isEventLike and formatEventRejection helpers that only it used. After this, each rejection is reported once, by Sentry's handler, which gives the more informative result in every case:

rejection reason built-in handler removed handler
cross-realm Error real type + message + stack Non-Error rejection: {}
undefined / primitive Non-Error promise rejection captured with value: undefined Non-Error rejection: undefined (no stack)
CustomEvent Event 'CustomEvent' (type=…) + serialized type/target/detail Event rejection: type=…

Once this ships, the EHY and EJ9 groups will stop receiving events. The real underlying errors (DJ2 and similar) keep their own issues, where they can be triaged or ignored on their merits.

Test plan

  • npm run ts-check, npm run lint, npm run test-min
  • After deploy: EHY and EJ9 stop receiving events, and the built-in twins (e.g. DJ2) keep reporting at their usual rate.

🤖 Generated with Claude Code

…XPLORER-EHY

Sentry's default GlobalHandlers integration already reports every unhandled
rejection, so CE's own 'unhandledrejection' listener sent a second, worse copy
of each one. Its `instanceof Error` check fails for Errors from another realm
(e.g. Safari extension content scripts), and JSON.stringify turns those into
"Non-Error rejection: {}". Each EHY event pairs with a properly titled
built-in event, such as COMPILER-EXPLORER-DJ2 ("Invalid call to
runtime.sendMessage(). Tab not found."), at the same timestamp.

Sentry's handler already covers what the custom one tried to add: it
recognises cross-realm Errors, and it serialises Event/CustomEvent rejections
(type, target, detail) into the event's extra data.

Also stops COMPILER-EXPLORER-EJ9 ("Non-Error rejection: undefined").

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The change can discard distinct consecutive CustomEvent rejections and lose diagnostics for cross-realm events and falsy detail values.

2 open issues
What changed in this PR

This PR removes Compiler Explorer’s duplicate unhandled promise rejection reporting, leaving capture to Sentry’s default handler.

Changes:

  • Removes the custom unhandledrejection listener that sent a second report.
  • Deletes the Event/CustomEvent detection and formatting helpers added in #8173, which were used only by that listener.
File Description
static/​sentry.ts Removes duplicate rejection capture and its dedicated formatting helpers.

Review effort: Balanced

Comment thread static/sentry.ts Resolved
Comment thread static/sentry.ts
@@ -138,26 +119,6 @@ export function SetupSentry() {
return event;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Both points are accurate for the 11.10 SDK, but I'm leaving them as is. The real-world CustomEvent case (DXM: 13.5k events, Safari's own same-realm unhandledrejection event, no detail) is fully covered by the built-in handler's __serialized__ extra. Dedupe only collapses back-to-back identical events within one page session, which is the SDK's intended behaviour, and those events group into the same issue anyway. Cross-realm Event rejections need an iframe realm we don't have, and extension isolated worlds don't deliver rejections to the page. Adding a beforeSend enrichment path for that would reintroduce the complexity this PR removes.

@OfekShilon
OfekShilon merged commit d445f91 into compiler-explorer:main Nov 21, 2026
12 checks passed
@compiler-explorer-bot compiler-explorer-bot Bot added the live This is now live label Nov 21, 2026
@compiler-explorer-bot

Copy link
Copy Markdown

This is now live

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

Labels

live This is now live ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants