Skip to content

Commit

Permalink
promise: hard deprecation for unhandled promise rejection
Browse files Browse the repository at this point in the history
PR-URL: #8217
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
jasnell committed Aug 29, 2016
1 parent ecf474c commit 07dbf73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/internal/process/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function setupPromises(scheduleMicrotasks) {
}
}

var deprecationWarned = false;
function emitPendingUnhandledRejections() {
let hadListeners = false;
while (pendingUnhandledRejections.length > 0) {
Expand All @@ -59,6 +60,14 @@ function setupPromises(scheduleMicrotasks) {
warning.name = 'UnhandledPromiseRejectionWarning';
warning.id = uid;
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 {
hadListeners = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ process.on('warning', common.mustCall((warning) => {
assert(/Unhandled promise rejection/.test(warning.message));
break;
case 1:
assert.strictEqual(warning.name, 'DeprecationWarning');
break;
case 2:
assert.strictEqual(warning.name, 'PromiseRejectionHandledWarning');
assert(/Promise rejection was handled asynchronously/
.test(warning.message));
}
}, 2));
}, 3));

const p = Promise.reject('This was rejected');
setImmediate(common.mustCall(() => p.catch(() => {})));

0 comments on commit 07dbf73

Please sign in to comment.