substack/node-seq — Issue #28: Infinite loop with multiple catch()'s 
Author: jfeldstein
Created: 2012-01-21 23:35:31+00:00
State: open

Should catch() not be used to catch errors after individual steps?

In my script, I have long Seq chains which perform multistep procedures, and I'd been using .catch() to respond to errors at multiple points in the chain. Turns out that when any error is encountered, the first catch in the chain is always the one that responds to it, even if execution has already passed that point. Afterwards, execution continues from that catch, often repeating chunks of the chain.

Seq = require('seq');

Seq()
.seq(function() {
this(null, 'hi');
})
.catch(function(e){
console.error("First catch", e);
})
.seq(function(){
this('an error');
})
.seq(function(n){
console.log("Should not run, proceed to catch.");
this(null, n);
})
.catch(function(e){
console.error("Second Catch", e);
})
.seq(function(n){
console.log("Continued after second catch.");
this(null, n);
})