Skip to content

Commit 5695cfa

Browse files
committed
fix(gulp): let gulp handle its own errors
1 parent 0e36814 commit 5695cfa

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

lib/cli.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ Cli.run = function run(processArgv) {
142142

143143
return Q.nfcall(gulp.start.bind(gulp), argv._[0] + ':before').then(
144144
function(){
145-
// Only some tasks return promises
145+
// Only some commands return promises
146+
return Q.fcall(taskInstance.run.bind(taskInstance), Cli, argv);
147+
},
148+
function(e){ //task error, let gulp handle it
149+
// Only some commands return promises
146150
return Q.fcall(taskInstance.run.bind(taskInstance), Cli, argv);
147151
}
148152
).then(function(){
@@ -199,7 +203,7 @@ function logEvents(gulpInst) {
199203
});
200204

201205
gulpInst.on('task_err', function(e) {
202-
var msg = formatError(e);
206+
var msg = formatGulpError(e);
203207
var time = prettyTime(e.hrDuration);
204208
gutil.log(
205209
'\'' + chalk.cyan(e.task) + '\'',
@@ -218,6 +222,26 @@ function logEvents(gulpInst) {
218222
// });
219223
}
220224

225+
// Format orchestrator errors
226+
function formatGulpError(e) {
227+
if (!e.err) {
228+
return e.message;
229+
}
230+
231+
// PluginError
232+
if (typeof e.err.showStack === 'boolean') {
233+
return e.err.toString();
234+
}
235+
236+
// Normal error
237+
if (e.err.stack) {
238+
return e.err.stack;
239+
}
240+
241+
// Unknown (string, number, etc.)
242+
return new Error(String(e.err)).stack;
243+
}
244+
221245
Cli.getBooleanOptionsForTask = function getBooleanOptionsForTask(task) {
222246
var availableTaskOptions = task.options;
223247
var booleanOptions = [];

0 commit comments

Comments
 (0)