Skip to content
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

lib: refactor unhandled rejection deprecation warning emission #28258

Closed
wants to merge 2 commits into from

Conversation

joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Jun 17, 2019

Emit the deprecation warning in the kDefaultUnhandledRejections
case to reduce the number of branches on unhandled rejection mode -
there is now only one switch case on it.

Also rename emitWarning() to emitUnhandledRejectionWarning()
to avoid ambiguity with process.emitWarning()

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot
Copy link
Collaborator

Sadly, an error occurred when I tried to trigger a build. :(

@nodejs-github-bot nodejs-github-bot added the process Issues and PRs related to the process subsystem. label Jun 17, 2019
Emit the deprecation warning in the `kDefaultUnhandledRejections`
case to reduce the number of branches on unhandled rejection mode -
there is now only one switch case on it.

Also rename `emitWarning()` to `emitUnhandledRejectionWarning()`
to avoid ambiguity with `process.emitWarning()`
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@joyeecheung
Copy link
Member Author

cc @nodejs/process

}

let deprecationWarned = false;
function emitDeprecationWarning() {
if (unhandledRejectionsMode === kDefaultUnhandledRejections &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this emit the warning every time rather than just once?

Also - doesn't this break the flag?

cc @BridgeAR

Copy link
Member Author

@joyeecheung joyeecheung Jun 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only call site of emitDeprecationWarning() is now L200 which is already guarded with deprecationWarned .

Also the only branch on unhandledRejectionsMode is on L180 so you can see what actions are done for each mode by simply looking at that switch instead of jumping in multiple nested functions.

@benjamingr benjamingr requested a review from BridgeAR June 18, 2019 08:33
@joyeecheung
Copy link
Member Author

Landed in 1c23b6f

joyeecheung added a commit that referenced this pull request Jun 19, 2019
Emit the deprecation warning in the `kDefaultUnhandledRejections`
case to reduce the number of branches on unhandled rejection mode -
there is now only one switch case on it.

Also rename `emitWarning()` to `emitUnhandledRejectionWarning()`
to avoid ambiguity with `process.emitWarning()`

PR-URL: #28258
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
targos pushed a commit that referenced this pull request Jul 2, 2019
Emit the deprecation warning in the `kDefaultUnhandledRejections`
case to reduce the number of branches on unhandled rejection mode -
there is now only one switch case on it.

Also rename `emitWarning()` to `emitUnhandledRejectionWarning()`
to avoid ambiguity with `process.emitWarning()`

PR-URL: #28258
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
@targos targos mentioned this pull request Jul 2, 2019
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like I forgot to submit my review.

if (!deprecationWarned) {
emitDeprecationWarning();
deprecationWarned = true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second if should be part of the first one. Otherwise the deprecation notice will be visible even though the user handled the rejection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants