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

fix: Avoid re-raising exception that occur in then callbacks. #13

Merged
merged 1 commit into from Feb 10, 2016

Conversation

dylanahsmith
Copy link
Collaborator

@eapache for review

Problem

Exceptions that were occurring in .then blocks were being re-raised, rather than just causing the returned promise to be rejected. If .then is called on a promise multiple times and an exception occurs in one of the callbacks, then that would prevent additional callbacks from being called.

This behaviour does not appear to be part of the promise spec, and a test with node shows this behaviour isn't consistent with javascript:

var resolve = null;
var promise = new Promise(function(resolveFn, rejectFn) {
    resolve = resolveFn;
});
promise.then(function(value) { console.log("first then"); })
promise.then(function(value) { throw "then error" })
promise.then(function(value) { console.log("last then"); })

try {
    resolve("value")
} catch(err) {
    console.log("caught:", err)
}

outputs

first then
last then

Solution

Remove the raise in the exception handler, fix the existing tests that asserted this behaviour, and add a new test to make sure the exception doesn't prevent additional callbacks from being called.

@eapache
Copy link

eapache commented Feb 10, 2016

LGTM

@dylanahsmith dylanahsmith merged commit cc7a42f into lgierth:master Feb 10, 2016
@dylanahsmith dylanahsmith deleted the no-re-raise-reject branch February 10, 2016 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants