-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream/web internal function correct implementation leads to debuggers incorrectly detecting an unhandled rejection #51093
Comments
I decided to dive in the code and found that if I replace the The hack being simply: function PromiseReject(e) {
try {
return primordials.PromiseReject(e);
} catch {
// Empty on purpose
}
} |
By spec, Another alternative could be |
This is an incredibly annoying error. !error.stack.match('node:internal/webstreams/writablestream:101') &&
!error.stack.match('node:internal/webstreams/adapters:110') &&
!error.stack.match('node:internal/webstreams/readablestream:158') Are there any better userland workarounds? |
It looks like this hack "worked" because of this catch detection issue in particular (now fixed): |
|
@r-cyr sorry I was not clear. The |
I just retried your original repro code. It is NOT treated as an uncaught exception by the VSCode debugger (VSCode 1.91.0-insider). 🎉 |
May be fixed by #53800 |
Closing, as that PR has landed. If you disagree, feel free to reopen. |
I still see "uncaught" rejections from node/lib/internal/webstreams/writablestream.js Line 1044 in 7168295
Any reason this wasn't included in #53800? |
Version
v20.10.0, v22.3.0
Platform
MacOS/WSL
Subsystem
No response
What steps will reproduce the bug?
Run the following code into a debugger (Inside VSCode or in Chrome) with
Pause on uncaught exceptions
checked/enabled:How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
When run in a debugger with
Pause on uncaught exceptions
checked, program should print "Hello world" then quit.What do you see instead?
The program will execute as expected then when the stream gets destroyed at the end, the debugger will pause after a second and show the following error as an unhandled rejection:
The program runs as expected if
Pause on uncaught exceptions
is unchecked/disabled.Additional information
The call stack shows that the error comes from https://github.com/nodejs/node/blob/main/lib/internal/webstreams/writablestream.js#L1033 but we can see that
setPromiseHandled
gets called a few lines after so I don't believe that error to be correct. While looking for possible reasons, I ended up finding this which may be the root causeI also tried listening to
process
events 'uncaughtException' and 'unhandledrejection' but those were never triggered.If it's really caused by the debugger, then I don't know if it's possible to refactor the function in a way that would make debuggers happy... (and me too since we started using webstreams a lot at work... and getting that error all the time when debugging is painful)
Worth noting that the function below it, named
writableStreamDefaultWriterEnsureClosedPromiseRejected
is written similarly towritableStreamDefaultWriterEnsureReadyPromiseRejected
and could, maybe, produce the same issue. (I didn't try to trigger it)The text was updated successfully, but these errors were encountered: