Skip to content

Commit

Permalink
fix(gulp): let gulp handle its own errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tlancina committed Mar 28, 2016
1 parent 0e36814 commit 5695cfa
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ Cli.run = function run(processArgv) {

return Q.nfcall(gulp.start.bind(gulp), argv._[0] + ':before').then(
function(){
// Only some tasks return promises
// Only some commands return promises
return Q.fcall(taskInstance.run.bind(taskInstance), Cli, argv);
},
function(e){ //task error, let gulp handle it
// Only some commands return promises
return Q.fcall(taskInstance.run.bind(taskInstance), Cli, argv);
}
).then(function(){
Expand Down Expand Up @@ -199,7 +203,7 @@ function logEvents(gulpInst) {
});

gulpInst.on('task_err', function(e) {
var msg = formatError(e);
var msg = formatGulpError(e);
var time = prettyTime(e.hrDuration);
gutil.log(
'\'' + chalk.cyan(e.task) + '\'',
Expand All @@ -218,6 +222,26 @@ function logEvents(gulpInst) {
// });
}

// Format orchestrator errors
function formatGulpError(e) {
if (!e.err) {
return e.message;
}

// PluginError
if (typeof e.err.showStack === 'boolean') {
return e.err.toString();
}

// Normal error
if (e.err.stack) {
return e.err.stack;
}

// Unknown (string, number, etc.)
return new Error(String(e.err)).stack;
}

Cli.getBooleanOptionsForTask = function getBooleanOptionsForTask(task) {
var availableTaskOptions = task.options;
var booleanOptions = [];
Expand Down

0 comments on commit 5695cfa

Please sign in to comment.