0
我遵循了this question處的推薦解決方案,但我仍然看到錯誤打破了我的觀察者。防止非流式錯誤打破飲用水手錶
由於觀察者是這樣的:
var through = require('through2');
var watch = require('gulp-watch');
gulp.task('catchall', function() {
return watch('gulpfile.js')
.pipe(through.obj(externalFunc))
.on('error', function(err) {
console.log('Inside error handler:', err);
});
});
隨着externalFunc定義爲:
function externalFunc(file, enc, done) {
throw new Error("I have been compromised - Abort mission!");
}
我希望看到的輸出:
[10:52:51] Starting 'catchall'...
[10:52:53] gulpfile.js was changed
Inside error handler: I have been compromised - Abort mission!
相反,我沒有得到任何輸出從externalFunc
,而是得到標準的錯誤輸出和堆棧跟蹤:
[10:52:51] Starting 'catchall'...
[10:52:53] gulpfile.js was changed
/my/path/to/gulpfile.js:27
throw new Error("I have been compromised - Abort mission!");
^
Error: I have been compromised - Abort mission!
at DestroyableTransform.externalFunc [as _transform] ....
最重要的是,觀察者崩潰。
爲什麼這個錯誤沒有被on('error')
監聽器困住,我可以在一個吞嚥監視器中如何處理這些錯誤而不退出?