fix(node-core): rejection warning in strict mode#21160
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 03a493d. Configure here.
03a493d to
5702627
Compare
f7b4f95 to
8a24c8b
Compare
isaacs
left a comment
There was a problem hiding this comment.
I'm a bit confused. I don't think that this actually does match the behavior in Node...?
$ node --unhandled-rejections=strict -e 'Promise.reject("ok")'
node:internal/process/promises:281
reason : new UnhandledPromiseRejection(reason);
^
UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "ok".
at strictUnhandledRejectionsMode (node:internal/process/promises:281:14)
at processPromiseRejections (node:internal/process/promises:413:17)
at process.processTicksAndRejections (node:internal/process/task_queues:105:32) {
code: 'ERR_UNHANDLED_REJECTION'
}
Node.js v26.0.0
Maybe I'm missing the intention. What is the situation that this is supposed to address?
|
@isaacs Okay, I don't think I've ever thrown a string as an error, but it seems the behavior is different in Node.js for Error objects vs strings: If it matters, I can adjust the PR to keep the current behavior if the object doesn't have a |
Only print it if the reason doesn't have a stack. This matches the behavior of Node.js.
8a24c8b to
e352e1e
Compare
|
Ah, I see yes, it is a different result if the thrown value is not an
If we're going to be matching Node's behavior, then we ought to print the long warning whenever the thrown value is not an It looks like these are the cases to cover:
Here's a test that loops through each of the cases for reference: #!/bin/bash
SETTINGS=(none warn strict)
VALUES=('true' 'new Error("x")')
for setting in "${SETTINGS[@]}"; do
for er in "${VALUES[@]}"; do
echo "CASE: unhandled-rejections=${setting} error=${er}"
node --unhandled-rejections=${setting} \
-e "Promise.reject($er); setTimeout(()=>console.error('did not exit'))" \
echo $?
echo "----"
done
doneResults: If you want to update it to match Node's behavior in each situation, I think we can get likely that in for v11. |
I've pushed that change. Node.js does not use
For all the cases, getting it exactly right will probably not be doable, definitely not for |
|
Ah, yes, you are right. I was mistaken, setting the
Yes, I guess what I'm saying is, we should endeavor to have the behavior with Node+Sentry to be the same as the behavior with Node alone. If we do something that changes behavior, we should simulate it (eg, listening prevents the crash, so if we're the only listener, then crash explicitly.) But of course, we don't need to warn if there's already a warning being printed.
I actually agree, that's almost certainly a better way forward if we can make it work. However, this is a subtle and somewhat tricky thing to get exactly right, and Error reporting is about the most important thing that our users rely on Sentry to do reliably, so we have to approach it with a lot of care, and so it somewhat lands in "not broken, don't fix it" for v11. More surface-level behavior choices that don't fundamentally alter how it works, but brings the behavior closer to Node's default behavior, is much lower risk. |

Only print it if the reason doesn't have a stack. This matches the behavior of Node.js.
Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint) & (yarn test).