Skip to content

Commit 9ce788e

Browse files
pd4d10targos
authored andcommitted
process: fix promise catching
Fixes: #30953 PR-URL: #30957 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9e5d39c commit 9ce788e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/internal/process/promises.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ function handledRejection(promise) {
123123
return;
124124
}
125125
}
126-
setHasRejectionToWarn(false);
126+
if (maybeUnhandledPromises.size === 0 && asyncHandledRejections.length === 0)
127+
setHasRejectionToWarn(false);
127128
}
128129

129130
const unhandledRejectionErrName = 'UnhandledPromiseRejectionWarning';

test/parallel/test-promises-unhandled-rejections.js

+12
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,15 @@ asyncTest(
718718
let timer = setTimeout(common.mustNotCall(), 10000);
719719
},
720720
);
721+
722+
// https://github.com/nodejs/node/issues/30953
723+
asyncTest(
724+
'Catching a promise should not take effect on previous promises',
725+
function(done) {
726+
onUnhandledSucceed(done, function(reason, promise) {
727+
assert.strictEqual(reason, '1');
728+
});
729+
Promise.reject('1');
730+
Promise.reject('2').catch(function() {});
731+
}
732+
);

0 commit comments

Comments
 (0)