promise: hard deprecation for unhandled promise rejection
PR-URL: https://github.com/nodejs/node/pull/8217 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
parent
ecf474ceba
commit
07dbf7313d
@ -45,6 +45,7 @@ function setupPromises(scheduleMicrotasks) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var deprecationWarned = false;
|
||||||
function emitPendingUnhandledRejections() {
|
function emitPendingUnhandledRejections() {
|
||||||
let hadListeners = false;
|
let hadListeners = false;
|
||||||
while (pendingUnhandledRejections.length > 0) {
|
while (pendingUnhandledRejections.length > 0) {
|
||||||
@ -59,6 +60,14 @@ function setupPromises(scheduleMicrotasks) {
|
|||||||
warning.name = 'UnhandledPromiseRejectionWarning';
|
warning.name = 'UnhandledPromiseRejectionWarning';
|
||||||
warning.id = uid;
|
warning.id = uid;
|
||||||
process.emitWarning(warning);
|
process.emitWarning(warning);
|
||||||
|
if (!deprecationWarned) {
|
||||||
|
deprecationWarned = true;
|
||||||
|
process.emitWarning(
|
||||||
|
'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.',
|
||||||
|
'DeprecationWarning');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
hadListeners = true;
|
hadListeners = true;
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,14 @@ process.on('warning', common.mustCall((warning) => {
|
|||||||
assert(/Unhandled promise rejection/.test(warning.message));
|
assert(/Unhandled promise rejection/.test(warning.message));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
assert.strictEqual(warning.name, 'DeprecationWarning');
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
assert.strictEqual(warning.name, 'PromiseRejectionHandledWarning');
|
assert.strictEqual(warning.name, 'PromiseRejectionHandledWarning');
|
||||||
assert(/Promise rejection was handled asynchronously/
|
assert(/Promise rejection was handled asynchronously/
|
||||||
.test(warning.message));
|
.test(warning.message));
|
||||||
}
|
}
|
||||||
}, 2));
|
}, 3));
|
||||||
|
|
||||||
const p = Promise.reject('This was rejected');
|
const p = Promise.reject('This was rejected');
|
||||||
setImmediate(common.mustCall(() => p.catch(() => {})));
|
setImmediate(common.mustCall(() => p.catch(() => {})));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user