Skip to content

Commit

Permalink
process: fix promise catching
Browse files Browse the repository at this point in the history
Fixes: #30953

PR-URL: #30957
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
pd4d10 authored and MylesBorins committed Dec 17, 2019
1 parent 88731ad commit 954793f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/internal/process/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ function handledRejection(promise) {
return;
}
}
setHasRejectionToWarn(false);
if (maybeUnhandledPromises.size === 0 && asyncHandledRejections.length === 0)
setHasRejectionToWarn(false);
}

const unhandledRejectionErrName = 'UnhandledPromiseRejectionWarning';
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-promises-unhandled-rejections.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,15 @@ asyncTest(
let timer = setTimeout(common.mustNotCall(), 10000);
},
);

// https://github.com/nodejs/node/issues/30953
asyncTest(
'Catching a promise should not take effect on previous promises',
function(done) {
onUnhandledSucceed(done, function(reason, promise) {
assert.strictEqual(reason, '1');
});
Promise.reject('1');
Promise.reject('2').catch(function() {});
}
);

0 comments on commit 954793f

Please sign in to comment.