Skip to content

Commit

Permalink
process: refactor unhandledRejection logic
Browse files Browse the repository at this point in the history
This commit prevents a deprecation warning from being emitted
if the unhandledRejection event was actually handled.

PR-URL: #28540
Fixes: #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>
  • Loading branch information
cjihrig authored and targos committed Jul 20, 2019
1 parent e2adfb7 commit 4cb0fc3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/internal/process/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-promise-handled-rejection-no-warning.js
Original file line number Diff line number Diff line change
@@ -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());

0 comments on commit 4cb0fc3

Please sign in to comment.