Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unhandledRejection fails to occur if .catch() is used on the last promise #30953

Closed
coreyfarrell opened this issue Dec 13, 2019 · 2 comments
Closed
Labels
confirmed-bug Issues with confirmed bugs. promises Issues and PRs related to ECMAScript promises.

Comments

@coreyfarrell
Copy link
Member

  • Version: 12.13.1 / 13.3.0
  • Platform: Linux lt2.cfware.com 5.3.11-200.fc30.x86_64 #1 SMP Tue Nov 12 19:25:25 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Take the following script:

'use strict';

Promise.reject('rejection 1');
Promise.reject('rejection 2').catch(() => {});

The expected result is an unhandledRejection for rejection 1. This script produces no warnings on node.js 12 or 13.

@addaleax addaleax added confirmed-bug Issues with confirmed bugs. promises Issues and PRs related to ECMAScript promises. labels Dec 13, 2019
@addaleax
Copy link
Member

Something like this might help?

diff --git a/lib/internal/process/promises.js b/lib/internal/process/promises.js
index 35ebb39115f3..7cd40f96cc98 100644
--- a/lib/internal/process/promises.js
+++ b/lib/internal/process/promises.js
@@ -125,7 +125,8 @@ function handledRejection(promise) {
       return;
     }
   }
-  setHasRejectionToWarn(false);
+  if (maybeUnhandledPromises.size === 0 && asyncHandledRejections.length === 0)
+    setHasRejectionToWarn(false);
 }
 
 const unhandledRejectionErrName = 'UnhandledPromiseRejectionWarning';

@nodejs/promises-debugging @joyeecheung (I think this might have come from bf56671)

@joyeecheung
Copy link
Member

@addaleax Yeah, that’s likely, as the PR only passed whatever test we had and this does not seem to be tested by us.

@targos targos closed this as completed in 81e3bca Dec 16, 2019
MylesBorins pushed a commit that referenced this issue Dec 17, 2019
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>
targos pushed a commit that referenced this issue Jan 14, 2020
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>
BethGriggs pushed a commit that referenced this issue Feb 6, 2020
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. promises Issues and PRs related to ECMAScript promises.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants