-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
process: Don't warn/throw on unhandled rejections when hook is set #33017
Conversation
--unhandled-rejections has three explicit modes (strict, warn, none) plus one implicit "default" mode, which logs an additional deprecation warning (DEP0018). Prior to this commit, the default mode was subtly different from warn mode. If the unhandledRejections hook is set, default mode suppresses all warnings. In warn mode, unhandledRejections would always fire a warning, regardless of whether the hook was set. In addition, prior to this commit, strict mode would always throw an exception, regardless of whether the hook was set. In this commit, all modes honor the unhandledRejections hook. If the user has set the hook, then the user has taken full responsibility over the behavior of unhandled rejections. In that case, no additional warnings or thrown exceptions will be fired, even in warn mode or strict mode. This commit is a stepping stone towards resolving DEP0018. After this commit, any code that includes an unhandledRejection hook will behave unchanged when we change the default mode. Refs: nodejs#26599
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flag as it was implemented intentionally did not check for the hook being present or not and the behavior was intensively discussed before it was agreed upon to behave exactly as it does right now.
I am strongly against checking for the hook's presence and therefore against this change. Any module might set such a hook (and many do) so that it would impact the user.
@BridgeAR Can you point me to where this was intensively discussed? I only see this comment on your PR.
No one replied to your "I would rather" remark, except to say "still LGTM." It's a fairly subtle point that hasn't really been discussed anywhere I can find.
That is already true today. That's how This PR only changes the behavior of If you think it would help, we could compromise by having a new mode for (I'd have to think harder about the name The reason I care about this is that I hope to change the default So yet another option is to skip this PR entirely and just do a PR that changes the default mode to semi-strict. Userland code could override the semi-strict behavior with a hook. If we did that, I'd almost certainly want to give the default mode an actual named value and add it to the documentation. (I think a lot of people wrongly think that the default mode is |
8ae28ff
to
2935f72
Compare
Instead of this PR, we merged PR #33475 which adds two new modes to |
TSC will be voting on the intended default behavior for unhandled rejections on v15, where we also intend to remove the deprecation warning. We want to listen to Node.js users experiences with unhandled promises and what you think should be the default before voting, so we prepared a survey: https://www.surveymonkey.com/r/FTJM7YD We also wrote an accompanying blog post for extra context: https://medium.com/@nodejs/node-js-promise-reject-use-case-survey-98e3328340c9 The survey will run for at least two weeks, at which point we'll evaluate if the number of replies is enough for us to move forward, otherwise we might extend it for a week or two. Please fill out the survey as it will help us decide the future of unhandled promise rejections on Node.js! |
--unhandled-rejections has three explicit modes (strict, warn, none)
plus one implicit "default" mode, which logs an additional deprecation
warning (DEP0018).
Prior to this commit, the default mode was subtly different from warn
mode. If the unhandledRejections hook is set, default mode suppresses
all warnings. In warn mode, unhandledRejections would always fire a
warning, regardless of whether the hook was set.
In addition, prior to this commit, strict mode would always throw an
exception, regardless of whether the hook was set.
In this commit, all modes honor the unhandledRejections hook. If the
user has set the hook, then the user has taken full responsibility over
the behavior of unhandled rejections. In that case, no additional
warnings or thrown exceptions will be fired, even in warn mode or
strict mode.
This commit is a stepping stone towards resolving DEP0018. After this
commit, any code that includes an unhandledRejection hook will behave
unchanged when we change the default mode.
Refs: #26599
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes