Skip to content

Commit a23a1c9

Browse files
committed
continue to run subtopics even if a parent topic has an error in it (fixes #231)
1 parent eb66421 commit a23a1c9

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ node_modules
22
.idea
33
.nul
44
.hgignore
5+
.hgsubstate
6+
.hg
57
test/npm-debug.log

lib/vows/suite.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,17 @@ this.Suite.prototype = new(function () {
230230
if (topic &&
231231
ctx.name !== 'on' &&
232232
(!topic._vowsEmitedEvents || !topic._vowsEmitedEvents.hasOwnProperty(ctx.event))) {
233-
topic.on(ctx.event, function (ctx) {
234-
return function (val) {
235-
return run(new(Context)(vow, ctx, env), lastTopic);
233+
var runInnerContext = function(ctx){
234+
return function(val){
235+
return run(new (Context)(vow, ctx, env), lastTopic);
236236
};
237-
}(ctx));
238-
} else {
239-
run(new(Context)(vow, ctx, env), lastTopic);
237+
}(ctx);
238+
topic.on(ctx.event, runInnerContext);
239+
// Run an inner context if the outer context fails, too.
240+
topic.on('error', runInnerContext);
241+
}
242+
else {
243+
run(new (Context)(vow, ctx, env), lastTopic);
240244
}
241245
}
242246
});

test/vows-error-test.js

+15
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ vows.describe('Error Handling').addBatch({
102102
assert.equal(results.honored, 0);
103103
}
104104
}
105+
},
106+
"A topic with an error in it" : {
107+
topic : function(){
108+
throw('awesome');
109+
},
110+
"should error" : function(error, result){
111+
assert.equal(error, 'awesome');
112+
},
113+
"containing a subtopic" : {
114+
topic : function(){
115+
return 52;
116+
},
117+
"should reach a vow in the subtopic" : function(){
118+
}
119+
}
105120
}
106121
}).export(module);
107122

0 commit comments

Comments
 (0)