done() must be called even if the asych task returns an error #2

kmiklas opened this Issue Dec 22, 2012 · 2 comments


None yet
2 participants

kmiklas commented Dec 22, 2012

The following is a bug:

34: if (!error) done();

If an error is thrown, done() must still be called to tell Grunt that the asych task has completed, despite the fact that it threw an error.

Best is to pass the error to Grunt for logging (.message property), as follows:

 done((error) ? error : '');

"If (error) has a value, as opposed to null, the ternary evaluates to true, the returns the error, and done(error) is called. If error is null, the ternary evaluates to false, returns an empty string, and simply call done()."

I also thought of the following possibilities, but didn't test them:

  1. done((error) ? error : true);
  2. done((error) ? error : null);
  3. done(error);

Is it possible that we could simply replace line 34 with #3, because the callback parameter "error" will be null in the absence of an error? I ran out of time, played it safe, and used the code above.

kmiklas commented Dec 22, 2012

I checked on the #grunt IRC channel, and they recommend the #3 solution in the previous post:


As the convention is to send null with success.


mattmcmanus commented Dec 30, 2012

Thanks! I just pushed 0.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment