-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Simplify rejection handler to propagate error by re-throwing reason. #554
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
CLAs look good, thanks! |
@@ -132,6 +132,6 @@ function racePromise_(promise, unlisten, timeout) { | |||
return result; | |||
}, (reason) => { | |||
unlisten(); | |||
return Promise.reject(reason); | |||
throw reason; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a guarantee that reason
would always be an Error
?
Interestingly enough, you can throw anything you want in JavaScript. |
throwing a |
Yeah, we've been trying to avoid that.
|
By the same token you shouldn't reject a Promise with something that isn't an |
hmm thats a good point. but i generally think of promise rejection as a way to cancel all the handlers subsequent to the current one (breaking the composition) and not an analog of actual |
Agree. Would gladly accept a PR that replaces Any thoughts on these? |
@sparhami friendly ping to follow up on @dvoytenko |
I'm not sure why it matters if you don't have control over the upstream. You can throw I would encourage you to change the upstream to throw an Error instead of a string. It is probably a good idea because then you can tell what actually caused the rejection chain rather than getting a string and having to search for it in the code base. If you would like, I could create a separate PR for that change. |
Apologies, missed the last report. This sounds good. LGTM. And we'd definitely would welcome a PR to update rejections to use an exception. |
Simplify rejection handler to propagate error by re-throwing reason.
No description provided.