Permalink
Browse files

Tasks can emit error-events

  • Loading branch information...
mde
mde committed Jun 9, 2012
1 parent 6bd2319 commit 084ee65e810bb137623b341aced40e2b7aa9ff2b
Showing with 26 additions and 1 deletion.
  1. +7 −1 lib/task/task.js
  2. +12 −0 tests/Jakefile
  3. +7 −0 tests/task_base.js
View
@@ -201,7 +201,13 @@ TaskBase = new (function () {
this.run = function () {
var runAction = this.shouldRunAction();
if (runAction) {
- this.action.apply(this, this.args);
+ try {
+ this.action.apply(this, this.args);
+ }
+ catch (e) {
+ this.emit('error', e);
+ return; // Bail out, not complete
+ }
}
if (!(runAction && this.async)) {
complete();
View
@@ -177,5 +177,17 @@ task('voom', ['blammo'], function () {
// Modify, add a prereq
task('voom', ['noActionNoPrereqs']);
+namespace('vronk', function () {
+ task('groo', function () {
+ var t = jake.Task['vronk:zong'];
+ t.addListener('error', function (e) {
+ console.log(e.message);
+ });
+ t.invoke();
+ });
+ task('zong', function () {
+ throw new Error('OMFGZONG');
+ });
+});
View
@@ -117,6 +117,13 @@ var tests = {
h.next();
}
+, 'test listening for task error-event': function () {
+ h.exec('../bin/cli.js vronk:groo', function (out) {
+ assert.equal('OMFGZONG', out);
+ });
+ h.next();
+ }
+
};
h.run(tests, function () {

0 comments on commit 084ee65

Please sign in to comment.