很好地在gulp任务中抛出错误 [英] Nicely throwing an error in gulp task
问题描述
gulp.task('favicon',function( ){
try {
require('child_process')。execSync('icotool --version');
} catch(e){
var err = new Error
throw err;
}
return gulp.src('',{read:false})
。 pipe(shell([
'./generate-favicon.sh'
]));
});
当通过gulp运行我的任务并运行错误时,错误将被呈现相当丑陋。
我想以这样的方式呈现错误, jslint gulp-util的 PluginError
。
它实际上可以创建一个 PluginError
在那里抛出来,但似乎不是很正确。
另一种解决方案不是很好设置
err.showStack = false;
至少有一个更好的错误输出。
从什么我已经看到它不是很大的错误从gulp。但是我发现我曾经为我工作的这个博客条目。
http://gotofritz.net/blog/geekery/how-to-generate-error-in-gulp-task/
我的示例:
var gulp = require('gulp');
var gulpUtil = require('gulp-util');
gulp.task('deploy',function(cb){
if(typeof(specialId)==='undefined'){
throw new gulpUtil.PluginError({
插件:'deploy',
message:'specialId is empty。'
});
}
}
I am creating a gulp task which might fail under certain circumstances.
gulp.task('favicon', function () {
try {
require('child_process').execSync('icotool --version');
} catch( e ) {
var err = new Error( 'Unix bash and icotool required for generating favicon' );
throw err;
}
return gulp.src('', {read: false})
.pipe(shell([
'./generate-favicon.sh'
]));
});
When running my task via gulp and running into the error, the error will be presented rather ugly.
I would like to present the error in a way as it is done by e.g. jslint gulp-util's PluginError
.
It actually works to just create a PluginError
there and throw it but that doesn't seem quite right.
Another solution not that nice would be to set
err.showStack = false;
for at least a little nicer error output. A gulp.task.Error
would be nice.
From what I've seen its not great to throw an error from gulp. But I found this blog entry that I used to work for me.
http://gotofritz.net/blog/geekery/how-to-generate-error-in-gulp-task/
My Example:
var gulp = require('gulp');
var gulpUtil = require('gulp-util');
gulp.task('deploy', function(cb) {
if(typeof(specialId) === 'undefined') {
throw new gulpUtil.PluginError({
plugin: 'deploy',
message: 'specialId is empty.'
});
}
}
这篇关于很好地在gulp任务中抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!