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

unexpected behavior with --unhandled-rejections=strict flag #41184

Closed
guoard opened this issue Dec 15, 2021 · 3 comments · Fixed by #41194
Closed

unexpected behavior with --unhandled-rejections=strict flag #41184

guoard opened this issue Dec 15, 2021 · 3 comments · Fixed by #41194
Labels
doc Issues and PRs related to the documentations.

Comments

@guoard
Copy link

guoard commented Dec 15, 2021

Version

v16.13.1

Platform

Linux 5.11.0-41-generic #45~20.04.1-Ubuntu SMP Wed Nov 10 10:20:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

// test.js
process.on('uncaughtException', () => {
  console.log('Exception');
});

Promise.reject()

when we use flag --unhandled-rejections=strict we expect not to see any UnhandledPromiseRejectionWarning and Raise the unhandled rejection as an uncaught exception. but:

node --unhandled-rejections=strict test.js
Exception
(node:83740) UnhandledPromiseRejectionWarning: undefined
(Use `node --trace-warnings ...` to show where the warning was created)
(node:83740) UnhandledPromiseRejectionWarning: Unhandled promise rejection. 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

and when we do not use --unhandled-rejections=strict flag:

node test.js
Exception

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

It should do exactly the opposite

What do you see instead?

No response

Additional information

It has different behavior in node v14

cjihrig added a commit to cjihrig/node that referenced this issue Dec 16, 2021
`lib/internal/process/promises.js` contains the following comment
about --unhandled-rejections=strict. This commit updates the
docs to reflect this:

// --unhandled-rejections=strict:
// Emit 'uncaughtException'. If it's not handled, print
// the error to stderr and exit the process.
// Otherwise, emit 'unhandledRejection'. If
// 'unhandledRejection' is not
// handled, emit 'UnhandledPromiseRejectionWarning'.

Fixes: nodejs#41184
@cjihrig
Copy link
Contributor

cjihrig commented Dec 16, 2021

This comment indicates that the warning is expected when using 'strict' mode if you handle the uncaught exception. I've opened #41194 to update the docs.

It has different behavior in node v14

I wasn't able to reproduce this with the 'strict' flag. Did you mean that the default behavior (no flag specified) switched between v14 and v16? If so, that is expected behavior.

@guoard
Copy link
Author

guoard commented Dec 16, 2021

@cjihrig yes default behavior is different between node v14.18.2 and v16.13.1 but documents was not up to date. and that was confusing...
actually node v16.13.1 Raise the unhandled rejection as an uncaught exception by default.

@Mesteery Mesteery added the doc Issues and PRs related to the documentations. label Dec 16, 2021
nodejs-github-bot pushed a commit that referenced this issue Dec 19, 2021
`lib/internal/process/promises.js` contains the following comment
about --unhandled-rejections=strict. This commit updates the
docs to reflect this:

// --unhandled-rejections=strict:
// Emit 'uncaughtException'. If it's not handled, print
// the error to stderr and exit the process.
// Otherwise, emit 'unhandledRejection'. If
// 'unhandledRejection' is not
// handled, emit 'UnhandledPromiseRejectionWarning'.

Fixes: #41184

PR-URL: #41194
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this issue Jan 14, 2022
`lib/internal/process/promises.js` contains the following comment
about --unhandled-rejections=strict. This commit updates the
docs to reflect this:

// --unhandled-rejections=strict:
// Emit 'uncaughtException'. If it's not handled, print
// the error to stderr and exit the process.
// Otherwise, emit 'unhandledRejection'. If
// 'unhandledRejection' is not
// handled, emit 'UnhandledPromiseRejectionWarning'.

Fixes: #41184

PR-URL: #41194
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this issue Jan 31, 2022
`lib/internal/process/promises.js` contains the following comment
about --unhandled-rejections=strict. This commit updates the
docs to reflect this:

// --unhandled-rejections=strict:
// Emit 'uncaughtException'. If it's not handled, print
// the error to stderr and exit the process.
// Otherwise, emit 'unhandledRejection'. If
// 'unhandledRejection' is not
// handled, emit 'UnhandledPromiseRejectionWarning'.

Fixes: #41184

PR-URL: #41194
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Linkgoron pushed a commit to Linkgoron/node that referenced this issue Jan 31, 2022
`lib/internal/process/promises.js` contains the following comment
about --unhandled-rejections=strict. This commit updates the
docs to reflect this:

// --unhandled-rejections=strict:
// Emit 'uncaughtException'. If it's not handled, print
// the error to stderr and exit the process.
// Otherwise, emit 'unhandledRejection'. If
// 'unhandledRejection' is not
// handled, emit 'UnhandledPromiseRejectionWarning'.

Fixes: nodejs#41184

PR-URL: nodejs#41194
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this issue Feb 1, 2022
`lib/internal/process/promises.js` contains the following comment
about --unhandled-rejections=strict. This commit updates the
docs to reflect this:

// --unhandled-rejections=strict:
// Emit 'uncaughtException'. If it's not handled, print
// the error to stderr and exit the process.
// Otherwise, emit 'unhandledRejection'. If
// 'unhandledRejection' is not
// handled, emit 'UnhandledPromiseRejectionWarning'.

Fixes: #41184

PR-URL: #41194
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@abhayb443
Copy link

export NODE_OPTIONS=--unhandled-rejections=none
from the terminal

or

In npmrc file in the project
node-options="--unhandled-rejections=none"

to resolve this error. It will stop prompting the error.

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

Successfully merging a pull request may close this issue.

4 participants