当我在其中一项任务中出错时:
gulp.task('foo', function(onDone) {
onDone('It did not work');
});
我得到了一个无关紧要的堆栈跟踪:
[13:10:25] 'foo' errored after 4.27 s
[13:10:25] Error: It did not work
at formatError (C:\npm\node_modules\gulp\bin\gulp.js:169:10)
at Gulp.<anonymous> (C:\npm\node_modules\gulp\bin\gulp.js:195:15)
at emitOne (events.js:96:13)
at Gulp.emit (events.js:188:7)
at Gulp.Orchestrator._emitTaskDone (D:\Code\my-project\node_modules\orchestrator\index.js:264:8)
at D:\Code\my-project\node_modules\orchestrator\index.js:275:23
at finish (D:\Code\my-project\node_modules\orchestrator\lib\runTask.js:21:8)
at cb (D:\Code\my-project\node_modules\orchestrator\lib\runTask.js:29:3)
at D:\Code\my-project\gulp-tasks\insert-docs.js:116:25
at Request._callback (D:\Code\my-project\gulpfile.js:112:17)
我怎么不显示?我更喜欢使用in build gulp功能而不是第三方模块或console.error()
。
答案 0 :(得分:2)
传递给回调的Error
个对象上的gulp checks for the presence of a showStack
property。这可能是为了支持gutil.PluginError
上的选项而引入的,但可以与任何Error
对象一起使用:
function withError(msg) {
var err = new Error(msg);
err.showStack = false;
return err;
}
gulp.task('foo', function(done) {
done(withError('It did not work'));
});