sentry-javascript
sentry-javascript copied to clipboard
Unhandled Promise Rejection in debugger on Node startup
Is there an existing issue for this?
- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- [X] I have reviewed the documentation https://docs.sentry.io/
- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
8.7.0
Framework Version
8.7.0
Link to Sentry event
No response
SDK Setup
Sentry.init({
dsn: dsn,
environment: environmentWithAppInstance,
debug: true,
maxValueLength: maxValueLength,
release: version,
integrations: [nodeProfilingIntegration()],
skipOpenTelemetrySetup: true,
tracesSampler: (context) => {
if (context.request?.url?.endsWith("/status")) {
return 0;
}
return defaultTraceSampleRate;
},
profilesSampleRate: profilesSampleRate,
beforeBreadcrumb(breadcrumb, _) {
if (!shouldAddBreadcrumb(breadcrumb)) {
return null;
}
return breadcrumb;
},
beforeSend(event: ErrorEvent, hint: Sentry.EventHint) {
if (!shouldSend(hint)) {
return null;
}
event = removeAuthorizationHeader(event);
return event;
},
});
Steps to Reproduce
- Run
nest start --debug --watch
Node: 20.9.0 NestJS: 10.3.8
Expected Result
The application should start without throwing an unhandled promise rejection.
Actual Result
It throws an unhandled promise rejection (see screenshot):
If I unmark "uncaught exception" in my editor it starts like expected.
This error isn't unhandled as it has a .catch(). You're likely hitting this in the debugger because you have Pause on caught exceptions enabled:
This error isn't unhandled as it has a
.catch(). You're likely hitting this in the debugger because you havePause on caught exceptionsenabled:![]()
Thanks for the quick response.
If you look at the provided screenshot, you'll see that I have Uncaught Exception marked in the breakpoints section. (bottom left corner)
(I noticed that the code has a catch() applied. And it made the issue even weirder to me)
I think you're seeing this: https://github.com/microsoft/vscode/issues/116783
Which has a linked v8 dev tools issue which is still open: https://issues.chromium.org/issues/41161875
The argument is that debugger should not break here because the exception is later caught.
Without the debugger attached, this does not result in an unhandled promise rejection.
I've opened a PR in opentelemetry-instrumentation-fetch-node which should stop this from hitting the debugger issue.
Hmm, I still experiencing this issue (using the latest release 8.17.0). The debugger stops because of an "unhandled promise rejection".
I don't understand how this could be uncaught when there is a catch block right below it 🤔
Maybe this is because of how fetch internals work?
I've opened a PR in
opentelemetry-instrumentation-fetch-nodewhich should stop this from hitting the debugger issue.
@timfish Did you test this PR if it resolves the issue?
@timfish Did you test this PR if it resolves the issue?
No sorry. I looked at the open Chromium debugger issues and the causes and then made assumptions based on that and what I know about how awaiting promises vs then work.
As @AbhiPrasad says above, the changes I made should have fixed this but the fact that it hasn't suggests this rejection is triggered by the fetch internals.
@timfish
I opened a PR where the issue has been resolved in my project (running against 8.19 of Sentry)
https://github.com/gas-buddy/opentelemetry-instrumentation-fetch-node/pull/16
We're going to drop opentelemetry-instrumentation-fetch-node in favour of @opentelemetry/instrumentation-undici which should help solve this issue. I'll respond in this issue when this makes it into a release.
We're going to drop
opentelemetry-instrumentation-fetch-nodein favour of@opentelemetry/instrumentation-undiciwhich should help solve this issue. I'll respond in this issue when this makes it into a release.
Thank you for the update. I think it's a good decision to go with the official package.
We've released https://github.com/getsentry/sentry-javascript/releases/tag/8.30.0 with using the official package.
We've released https://github.com/getsentry/sentry-javascript/releases/tag/8.30.0 with using the official package.
Great work - it works!