Skip to content

Commit 4cb0fc3

Browse files
cjihrigtargos
authored andcommitted
process: refactor unhandledRejection logic
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>
1 parent e2adfb7 commit 4cb0fc3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/internal/process/promises.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,12 @@ function processPromiseRejections() {
199199
}
200200
case kDefaultUnhandledRejections: {
201201
const handled = process.emit('unhandledRejection', reason, promise);
202-
if (!handled) emitUnhandledRejectionWarning(uid, reason);
203-
if (!deprecationWarned) {
204-
emitDeprecationWarning();
205-
deprecationWarned = true;
202+
if (!handled) {
203+
emitUnhandledRejectionWarning(uid, reason);
204+
if (!deprecationWarned) {
205+
emitDeprecationWarning();
206+
deprecationWarned = true;
207+
}
206208
}
207209
break;
208210
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// This test verifies that DEP0018 does not occur when rejections are handled.
5+
common.disableCrashOnUnhandledRejection();
6+
process.on('warning', common.mustNotCall());
7+
process.on('unhandledRejection', common.mustCall());
8+
Promise.reject(new Error());

0 commit comments

Comments
 (0)