Good mistake when doing gulp task

I am creating a gulp task that may crash 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 I perform my task with gulp and run the error, the error will appear pretty ugly. I would like to present the error in the way it is done, for example, jslint gulp -util PluginError .

It actually works by simply throwing a PluginError there and throwing it, but that doesn't seem completely correct. Another solution not so pleasant would be to establish

 err.showStack = false; 

at least to get a lighter mistake. A gulp.task.Error will be enjoyable.

+7
javascript error-handling gulp
source share
1 answer

From what I saw, he did not select the error from gulp very well. But I found this blog entry in which I worked for me.

http://gotofritz.net/blog/geekery/how-to-generate-error-in-gulp-task/

Edit : gulp-util deprecated . Use the plugin-error package instead.

My example:

 var gulp = require('gulp'); var error = require('plugin-error'); gulp.task('deploy', function(cb) { if(typeof(specialId) === 'undefined') { var err = new PluginError({ plugin: 'deploy', message: 'specialId is empty.' }); } } 
+9
source share

All Articles