2016-08-23 43 views
1

當我在我的任務之一報錯了:如何在Gulp任務錯誤回調中顯示堆棧跟蹤?

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) 

我怎麼不顯示?我傾向於使用內建gulp功能而不是第三方模塊或console.error()

回答

1

Gulp checks for the presence of a showStack property on Error傳遞給回調的對象。這可能是爲了支持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')); 
});