当我在一个任务中出错时:
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:npmnode_modulesgulpbingulp.js:169:10)
at Gulp.<anonymous> (C:npmnode_modulesgulpbingulp.js:195:15)
at emitOne (events.js:96:13)
at Gulp.emit (events.js:188:7)
at Gulp.Orchestrator._emitTaskDone (D:Codemy-projectnode_modulesorchestratorindex.js:264:8)
at D:Codemy-projectnode_modulesorchestratorindex.js:275:23
at finish (D:Codemy-projectnode_modulesorchestratorlibrunTask.js:21:8)
at cb (D:Codemy-projectnode_modulesorchestratorlibrunTask.js:29:3)
at D:Codemy-projectgulp-tasksinsert-docs.js:116:25
at Request._callback (D:Codemy-projectgulpfile.js:112:17)
我怎么能不显示呢?我更喜欢使用内置的gulp功能,而不是第三方模块或console.error()
。
Gulp检查传递给回调的Error
对象上是否存在showStack
属性。这可能是为了在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'));
});