mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
process: refactor unhandledRejection logic
This commit prevents a deprecation warning from being emitted if the unhandledRejection event was actually handled. PR-URL: https://github.com/nodejs/node/pull/28540 Fixes: https://github.com/nodejs/node/issues/28539 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
e2adfb79b0
commit
4cb0fc3ab1
2 files changed
+14
-4
No files matched your search
@@ -199,10 +199,12 @@ function processPromiseRejections() {
|
||||
}
|
||||
case kDefaultUnhandledRejections: {
|
||||
const handled = process.emit('unhandledRejection', reason, promise);
|
||||
if (!handled) emitUnhandledRejectionWarning(uid, reason);
|
||||
if (!deprecationWarned) {
|
||||
emitDeprecationWarning();
|
||||
deprecationWarned = true;
|
||||
if (!handled) {
|
||||
emitUnhandledRejectionWarning(uid, reason);
|
||||
if (!deprecationWarned) {
|
||||
emitDeprecationWarning();
|
||||
deprecationWarned = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
// This test verifies that DEP0018 does not occur when rejections are handled.
|
||||
common.disableCrashOnUnhandledRejection();
|
||||
process.on('warning', common.mustNotCall());
|
||||
process.on('unhandledRejection', common.mustCall());
|
||||
Promise.reject(new Error());
|
||||
Reference in new issue
Block a user