Repository navigation
Stop double-reporting unhandled promise rejections - #9628
OfekShilon merged 1 commit into
Conversation
…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]>
There was a problem hiding this comment.
🟡 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
unhandledrejectionlistener 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
| @@ -138,26 +119,6 @@ export function SetupSentry() { | |||
| return event; | |||
There was a problem hiding this comment.
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.
|
This is now live |

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 ownunhandledrejectionlistener, but Sentry's defaultGlobalHandlersintegration already captures every unhandled rejection (onunhandledrejection: true; we don't overrideintegrations). That means every rejection gets reported twice:isError, and turns Event/CustomEvent rejections intoEvent 'CustomEvent' (type=…) captured as promise rejection. It also puts the type, target and detail intoextra.__serialized__.reason instanceof Error, and that check fails for Errors created in another realm, such as Safari extension content scripts. It then runsJSON.stringify(reason)on them, and since Error properties are non-enumerable the result is{}.Evidence from Sentry:
Invalid call to runtime.sendMessage(). Tab not found.from a Safari extension, with mechanismauto.browser.global_handlers.onunhandledrejection.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
isEventLikeandformatEventRejectionhelpers that only it used. After this, each rejection is reported once, by Sentry's handler, which gives the more informative result in every case:ErrorNon-Error rejection: {}undefined/ primitiveNon-Error promise rejection captured with value: undefinedNon-Error rejection: undefined(no stack)CustomEventEvent 'CustomEvent' (type=…)+ serialized type/target/detailEvent 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🤖 Generated with Claude Code