process: Change default --unhandled-rejections=throw - #33021
Conversation
|
While working on PR #32986, I found that I had to do an unnecessarily large amount of work updating the tests. This first led me to implement PR #33017 as a stepping stone, but @BridgeAR expressed disapproval, so I figured I'd close PR #32986 and open this PR. This PR, I claim, is the simplest thing that could possibly work. I think it will be more appealing than my earlier PR #32986 because it provides a way for users who don't want strict mode to escape it: users can set an At the same time, users who set a CLI flag will maintain full control over unhandled rejections, even if userland code attempts to override it.
|
devsnek
left a comment
There was a problem hiding this comment.
I have the same blocking concerns here as I did in the other PR.
|
@devsnek would you mind to add a link? |
|
cc @nodejs/tsc |
|
This should never be on by default; the language spec does not intend |
|
The language spec does not intend |
|
I don't agree - an uncaught throw is intended to catch the process. Promise rejections are not the same as synchronous thrown exceptions, and shouldn't be treated the same. I'm not objecting to the (existing) ways people can opt in to making the process exit, on any criteria they want. By default, however, this would be a very destructive setting. |
Can you provide a link? There's no statement about this in any version of the ECMAScript specification that I'm aware of. (But of course there wouldn't be. Browsers never "crash the process.") Node allows users to attach an
"Destructive" isn't the right word to use here. This PR will have no effect on anyone using the Everyone who has seen that warning since Node 10 was released and has taken some action to suppress it, any action at all, will not be impacted by this PR. |
This comment has been minimized.
This comment has been minimized.
That's not true. In this jsbin, the second script runs. https://jsbin.com/juxinik/1/edit?html,output (edit: pasted wrong link) |
|
Oh, interesting. I swear I had issues with that in the past, might be confusing with something else though. |
|
I would note that this definitely helps developers, and it is the default behavior in Deno. My opinion is that we should get this landed for v15. |
|
While I have many issues with Promises and absolutely think that crashing on unhandled rejections is good for developers, I'm less convinced that we should crash by default and I do think we should remove the existing deprecation warning. The default behavior should continue to be to warn on the unhandled rejection. So, just to be clear, I'm -1 on this PR |
|
@jasnell How do you feel about #32986 (comment)? |
|
Specifically on setting |
|
I'm in favor of raising an exception by default (so +1 on this PR). As a fallback, I'm in favor of removing the deprecation and keep the warning, as long as the process returns an error code by default when it exits if there are pending unhandled rejections. I'm -1 on just removing the deprecation and exiting successfully. |
|
@jasnell We do currently say in the deprecation warning that that’s what we’re going to do, and we could still keep it in the warning text (to be clear, I’m not suggesting to remove the warning, ever) 🤷♀️ |
|
I'm also in favor of the default mode continuing to be warn. |
|
Thinking through this while discussing on the tsc call, I think the process that I would like to see here is:
|
|
@jasnell my position (and one which imo reflects the intention of the JS spec) is that the |
|
@ljharb I'm not so sure about that... HostPromiseRejectionTracker exists for a reason. |
|
For all the folks who, like me, prefer the behaviour to be more consistent with the browser ecosystem, I recommend the following line: process.on('unhandledRejection', reason => console.trace(reason)); |
|
I believe that is similar to setting |
|
@luiscastro193 note that in order to be consistent with browsers it is sufficient to do Also note that the default changed because not terminating the process is unsafe and leads to possible cascading failures - so beware dragons ahead. |
|
It's worth noting that $ node -e 'process.on("unhandledRejection", function iShouldntShowOnStackTraceYetHereIAm(e) { console.trace(e) }); function foo() { Promise.reject(new Error()) } foo()'
Trace: Error
at foo ([eval]:1:137)
at [eval]:1:152
at Script.runInThisContext (vm.js:120:18)
at Object.runInThisContext (vm.js:309:38)
at Object.<anonymous> ([eval]-wrapper:10:26)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at evalScript (internal/process/execution.js:94:25)
at internal/main/eval_string.js:23:3
at process.iShouldntShowOnStackTraceYetHereIAm ([eval]:1:92)
at process.emit (events.js:314:20)
at processPromiseRejections (internal/process/promises.js:209:33)
at processTicksAndRejections (internal/process/task_queues.js:98:32)
$ node -e 'process.on("unhandledRejection", function iShouldntShowOnStackTraceYetHereIAm(e) { console.warn(e) }); function foo() { Promise.reject(new Error()) } foo()'
Error
at foo ([eval]:1:136)
at [eval]:1:151
at Script.runInThisContext (vm.js:120:18)
at Object.runInThisContext (vm.js:309:38)
at Object.<anonymous> ([eval]-wrapper:10:26)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at evalScript (internal/process/execution.js:94:25)
at internal/main/eval_string.js:23:3 |
This is a semver-major change that resolves DEP0018. All users that have set an unhandledRejection hook or set a non-default value for the --unhandled-rejections flag will see no change in behavior after this change. Refs: https://nodejs.org/dist/latest/docs/api/deprecations.html#deprecations_dep0018_unhandled_promise_rejections PR-URL: nodejs#33021 Fixes: nodejs#20392 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Mary Marchini <oss@mmarchini.me> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
This is now the default nodejs/node#33021
This is now the default nodejs/node#33021
This is now the default nodejs/node#33021
This is now the default nodejs/node#33021
This is now the default nodejs/node#33021
This is now the default nodejs/node#33021
This is a semver-major change that resolves DEP0018.
All users that have set an unhandledRejection hook or set a non-default
value for the --unhandled-rejections flag will see no change in behavior
after this change.
Fixes: #20392
Refs: https://nodejs.org/dist/latest/docs/api/deprecations.html#deprecations_dep0018_unhandled_promise_rejections
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes