2016-03-26 79 views
0

當我的一個Gulp任務失敗時,它會打印出這樣的控制檯錯誤。如何刪除失敗的Gulp任務上的調用堆棧?

PhantomJS 2.1.1 (Linux 0.0.0): Executed 12 of 12 (1 FAILED) (0.355 secs/0.43 secs) 
[20:18:42] 'client-test' errored after 15 s 
[20:18:42] Error: Karma exited with status code 1 
    at /home/blacksonic/workspace/angular2-webpack-es6-starter/tasks/client_test.js:15:21 
    at removeAllListeners (/home/blacksonic/workspace/angular2-webpack-es6-starter/node_modules/karma/lib/server.js:336:7) 
    at Server.<anonymous> (/home/blacksonic/workspace/angular2-webpack-es6-starter/node_modules/karma/lib/server.js:347:9) 
    at Server.g (events.js:260:16) 
    at emitNone (events.js:72:20) 
    at Server.emit (events.js:166:7) 
    at emitCloseNT (net.js:1519:8) 
    at nextTickCallbackWith1Arg (node.js:431:9) 
    at process._tickCallback (node.js:353:17) 

有沒有辦法刪除這個長的調用堆棧,只顯示錯誤消息?

回答

0

在你的管道中使用Gulp的內置錯誤事件就像這樣;

gulp.src(file.path) 
     .pipe('-- Your script --') 
     .on('error', function(){ 
       // Log a smaller version of the error 
       // or do nothing. Whatever you want 
      }) 
     .pipe('-- Your other script --') 
     .pipe(gulp.dest('-- You know the drill --')) 

你應該用一個漂亮的記錄儀裝備自己如gulp-util

記錄器這將打開上面的代碼爲:

var $ = require('gulp-load-plugins'); 

gulp.src(file.path) 
      .pipe('-- Your script --') 
      .on('error', function(){ 
        $.util.log('Hey! something broke'); 
       }) 
      .pipe('-- Your other script --') 
      .pipe(gulp.dest('-- You know the drill --'))