Skip to content

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

@karolis-zukauskas

Description

@karolis-zukauskas

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

9.11.0

Framework Version

@sentry/electron 6.5.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

initSentry({
  beforeSend(event, hint) {
    // Seems unintuitive - I'd expect rejection reason here
    const test = hint.originalException instanceof Promise; // true

    return event;
  },
});

Steps to Reproduce

  1. Throw an error from an async function and do not catch it - global "unhandledRejection" Sentry handler should capture it
  2. beforeSend is invoked - inspect EventHint.originalException to find its a Promise object. Was expecting rejection reason.

See source code:

Expected Result

I expected rejection reason (e.g. the thrown error object) inside EventHint.originalException, not a Promise object. I figured I can do the following:

let originalException;
if (hint.originalException instanceof Promise) {
  try {
    await hint.originalException;
  } catch (e) {
    originalException = e;
  }
}

But this feels dirty - what am I supposed to do with the Promise object?

Actual Result

See above.

Additional Context

No response

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions