Skip to content

fix(node-core): Pass rejection reason instead of Promise as originalException#20366

Open
logaretm wants to merge 1 commit intodevelopfrom
awad/js-2193-pass-error-instead-of-promise-in-unhandledrejection
Open

fix(node-core): Pass rejection reason instead of Promise as originalException#20366
logaretm wants to merge 1 commit intodevelopfrom
awad/js-2193-pass-error-instead-of-promise-in-unhandledrejection

Conversation

@logaretm
Copy link
Copy Markdown
Member

@logaretm logaretm commented Apr 16, 2026

This PR passes the rejection reason to captureException as originalException. Previously it was passing the promise which was useless to users.

This aligns Node with browser/onUncaughtException behavior as well.

closes #20325

…xception

In the onUnhandledRejection handler, captureException was being called with
originalException set to the rejected Promise object instead of the rejection
reason. This meant hint.originalException in beforeSend and downstream
integrations (localVariablesAsync, extraErrorData, zoderrors) received a
Promise rather than the actual error, breaking any logic that inspects it.
This aligns Node with the browser SDK and the onUncaughtException handler.

Fixes #20325

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 16, 2026

@logaretm logaretm marked this pull request as ready for review April 16, 2026 16:58
@logaretm logaretm requested review from JPeer264, Copilot and mydea April 16, 2026 16:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjusts Node’s OnUnhandledRejection integration to attach the rejection reason (rather than the Promise object) as EventHint.originalException, matching browser/onUncaughtException behavior and improving beforeSend usability.

Changes:

  • Update unhandled rejection handler to pass reason as originalException.
  • Add Vitest coverage to assert originalException is the rejection reason and the mechanism is set correctly.
  • Add a test asserting the integration installs a global unhandledRejection listener.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/node-core/src/integrations/onunhandledrejection.ts Fixes the hint payload to use the rejection reason as originalException.
packages/node-core/test/integrations/onunhandledrejection.test.ts Adds tests validating listener installation and the updated originalException behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/node-core/test/integrations/onunhandledrejection.test.ts
Comment thread packages/node-core/test/integrations/onunhandledrejection.test.ts
Comment thread packages/node-core/test/integrations/onunhandledrejection.test.ts
@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.78 kB - -
@sentry/browser - with treeshaking flags 24.27 kB - -
@sentry/browser (incl. Tracing) 43.61 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 45.32 kB - -
@sentry/browser (incl. Tracing, Profiling) 48.51 kB - -
@sentry/browser (incl. Tracing, Replay) 82.74 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.25 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 87.43 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 99.67 kB - -
@sentry/browser (incl. Feedback) 42.59 kB - -
@sentry/browser (incl. sendFeedback) 30.45 kB - -
@sentry/browser (incl. FeedbackAsync) 35.45 kB - -
@sentry/browser (incl. Metrics) 27.07 kB - -
@sentry/browser (incl. Logs) 27.2 kB +0.01% +1 B 🔺
@sentry/browser (incl. Metrics & Logs) 27.89 kB - -
@sentry/react 27.53 kB - -
@sentry/react (incl. Tracing) 45.88 kB - -
@sentry/vue 30.61 kB - -
@sentry/vue (incl. Tracing) 45.45 kB - -
@sentry/svelte 25.8 kB - -
CDN Bundle 28.46 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing) 44.69 kB - -
CDN Bundle (incl. Logs, Metrics) 29.83 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 45.78 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 68.73 kB - -
CDN Bundle (incl. Tracing, Replay) 81.65 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 82.73 kB +0.01% +1 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 87.17 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 88.23 kB - -
CDN Bundle - uncompressed 83.12 kB - -
CDN Bundle (incl. Tracing) - uncompressed 133.64 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 87.27 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 137.05 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 210.63 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 250.87 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 254.27 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 263.78 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 267.17 kB - -
@sentry/nextjs (client) 48.42 kB - -
@sentry/sveltekit (client) 44.06 kB - -
@sentry/node-core 57.94 kB +0.02% +8 B 🔺
@sentry/node 174.78 kB +0.01% +6 B 🔺
@sentry/node - without tracing 97.89 kB +0.03% +22 B 🔺
@sentry/aws-serverless 115.12 kB +0.01% +9 B 🔺

View base workflow run

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Promise object is passed as originalException instead of rejection reason in unhandledRejection handler

2 participants