substantial / sinon-stub-promise

Synchronous Promise stubbing for Sinon.JS
MIT License
85 stars 11 forks source link

Stop execution of chained thens after error #8

Closed matthewrfindley closed 9 years ago

a-b-r-o-w-n commented 9 years ago

My question is not a blocker, just curiosity. This looks good! :+1:

matthewrfindley commented 9 years ago

I agree, I am curious as well, but only wanted to find a quick solution to the problem.

amay commented 9 years ago

FYI: there is a strange scenario with then/catch chaining and promises that this made me think of.

Try this:

Promise.resolve('foo').then(() => {throw new Error('error')}).catch((e) => console.log(e)).then(() => console.log('in second then'))

You will see that the catch logs the error, as expected, but then the "in second then" log is also show. The behavior is that unless the catch throws the error again, subsequent items chained on will start executing again normally.

This change would break that behavior, but I don't believe we are actually using that behavior anywhere (yet). And we are definitely relying on the behavior of a thrown error skipping execution of subsequent then blocks, so I'm totally on board with this change. I just wanted to point this out for future reference.