Friday, February 23, 2024
148
rated 0 times [  155] [ 7]  / answers: 1 / hits: 9562  / 9 Years ago, sun, april 19, 2015, 12:00:00

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.


More From » error-handling

 Answers
19

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/



Edit: gulp-util has been deprecated. Instead, use the plugin-error package.



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.'
});
}
}

[#37806] Friday, April 17, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
billtreytonb

Total Points: 211
Total Questions: 104
Total Answers: 114

Location: Sudan
Member since Tue, Aug 3, 2021
3 Years ago
;