Repository navigation
Conversation
Calling a promisified function whose original returns a Promise is a likely mistake rather than use of a deprecated API, so DEP0174 is revoked and the DeprecationWarning is replaced with a regular process warning using the code PROMISIFY_RETURNED_PROMISE. The warning is now emitted once per promisified function rather than on every call, and can be silenced with --disable-warning=PROMISIFY_RETURNED_PROMISE. Rejections of the returned Promise are now forwarded to the promise returned by the promisified function instead of being left unhandled. If the callback has already settled the result, the rejection is rethrown so that it is still reported as an unhandled rejection rather than silently swallowed. Refs: nodejs#49609 Refs: nodejs#49647 Refs: nodejs#49607 Assisted-by: Claude Signed-off-by: James M Snell <jasnell@gmail.com>
|
Review requested:
|
Co-authored-by: James M Snell <jasnell@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67489 +/- ##
==========================================
- Coverage 90.67% 90.65% -0.02%
==========================================
Files 799 799
Lines 280245 280263 +18
Branches 54125 54120 -5
==========================================
- Hits 254100 254084 -16
- Misses 16280 16297 +17
- Partials 9865 9882 +17
🚀 New features to boost your workflow:
|
This comment was marked as outdated.
This comment was marked as outdated.
|
@nodejs/tsc for additional review... |
aduh95
left a comment
There was a problem hiding this comment.
Looks like we lack coverage for:
promisify(async (callback) => {
setImmediate(() => callback(new Error(1)));
throw new Error(2);
})()Previously it would have reported Error 1 (and emit a unhandledRejection, unless --unhandled-rejections=none); with the change in this PR it reports Error 2 and swallows Error 1.
We give no way to opt-out of the new behavior, not sure this is worth it, I don't think the ecosystem has any problem with the current behavior.
I'm not convinced. If there's a way to report Error 2 only if callback is called with a null/missing first parameter, so we're sure we don't swallow, that would be different. But tbh, I find it hard to justify changing this API at all, I doubt revoking the deprecation is worth it.
| process.on('warning', common.mustCall((warning) => { | ||
| assert.strictEqual(warning.name, 'Warning'); | ||
| assert.strictEqual(warning.code, 'PROMISIFY_RETURNED_PROMISE'); | ||
| assert.strictEqual( | ||
| warning.message, | ||
| 'Calling promisify on a function that returns a Promise is likely a mistake.'); | ||
| }, 5)); |
There was a problem hiding this comment.
Let's not validate the message
| process.on('warning', common.mustCall((warning) => { | |
| assert.strictEqual(warning.name, 'Warning'); | |
| assert.strictEqual(warning.code, 'PROMISIFY_RETURNED_PROMISE'); | |
| assert.strictEqual( | |
| warning.message, | |
| 'Calling promisify on a function that returns a Promise is likely a mistake.'); | |
| }, 5)); | |
| process.on('warning', common.expectsError({ | |
| name: 'Warning', | |
| code: 'PROMISIFY_RETURNED_PROMISE', | |
| }, 5)); |
Calling a promisified function whose original returns a Promise is a likely mistake rather than use of a deprecated API, so DEP0174 is revoked and the DeprecationWarning is replaced with a regular process warning using the code PROMISIFY_RETURNED_PROMISE. The warning is now emitted once per promisified function rather than on every call, and can be silenced with --disable-warning=PROMISIFY_RETURNED_PROMISE.
Rejections of the returned Promise are now forwarded to the promise returned by the promisified function instead of being left unhandled. If the callback has already settled the result, the rejection is rethrown so that it is still reported as an unhandled rejection rather than silently swallowed.
Refs: #49609
Refs: #49647
Refs: #49607