Node: Remove the DEP0018 deprecation

Created on 4 Mar 2020  路  3Comments  路  Source: nodejs/node

Is your feature request related to a problem? Please describe.
Deprecation DEP0018, which is associated with the poorly named UnhandledPromiseRejectionWarning, is misleading and fundamentally incorrect. Asynchronously handling promises _cannot_ be deprecated, as it is a basic tenant of the promise spec.

When a promise that is handled asynchronously is rejected before the handler is attached, the following is currently logged:

(node:45) 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(). (rejection id: 1)
(node:45) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Describe the solution you'd like
While preserving the warning may be useful, the deprecation (which will never happen) should be removed.

When a promise that is handled asynchronously is rejected before the handler is attached, only the following should be logged:

(node:45) 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(). (rejection id: 1)

Describe alternatives you've considered
Finalizing this proposed deprecation is tracked by #20392. This proposal is deeply flawed and would have far-reaching consequences if implemented. In #31148 I proposed a strategy to address the same pain points in a correct, more generic way. Regardless of whether my approach is taken or not, async handling of promises is a core feature that simply _cannot be deprecated_, and we should remove the erroneous deprecation accordingly.

promises

Most helpful comment

At this point, the overwhelming and stable consensus within Node.js core has been to maintain the deprecation. However, it is possible to use the --unhandled-rejections=none command-line argument (and within the NODE_OPTIONS environment variable to achieve the behavior you're looking for..

$ node --unhandled-rejections=none

$ NODE_OPTIONS=--unhandled-rejections=none node

All 3 comments

Looks like there is some push back on this mostly due to performance concerns. Would it make everyone happy if you implemented this behind a flag?

At this point, the overwhelming and stable consensus within Node.js core has been to maintain the deprecation. However, it is possible to use the --unhandled-rejections=none command-line argument (and within the NODE_OPTIONS environment variable to achieve the behavior you're looking for..

$ node --unhandled-rejections=none

$ NODE_OPTIONS=--unhandled-rejections=none node

Closing as there is no further action to take on this specific issue. The strategy around unhandled rejections is being refined in other PRs and issues

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandeepks1 picture sandeepks1  路  3Comments

srl295 picture srl295  路  3Comments

addaleax picture addaleax  路  3Comments

mcollina picture mcollina  路  3Comments

cong88 picture cong88  路  3Comments