Closed NeXTs closed 6 years ago
Ohh, sure :)
console.log(err.toString());
Well, I achieved what I wanted, maybe it will be helpful for someone.
var notify = require('gulp-notify');
var beep = require('beepbeep');
var onError = function(err) {
notify.onError({
title: "Gulp error in " + err.plugin,
message: err.toString()
})(err);
beep(3);
this.emit('end');
};
gulp.task('scripts', function() {
return gulp.src(src + '/js/**/*.js')
.pipe(plumber({ errorHandler: onError }))
...
This looks like a really neat solution @NeXTs I'm thinking of using in my build. Having an issue with plumber atm as it's not responding upon fixes to my errors. Check out my SO post on the issue that I'm having.
So I used your solution @NeXTs and also refactored my gulpfile while I was at it. However I don't think your onError
function is working...Not getting beeps inside terminal and the error heading that I'm getting it not "Gulp error in"
.
Not sure what's really wrong here..Looks all good to me..Can you take a look.
var notify = require('gulp-notify');
var beep = require('beepbeep');
// error handeler function
var onError = function(err){
notify.onError({
title: "gulp error in " + err.plugin,
message: err.toString()
})(err);
beep(3);
this.emit('end');
};
// styles task.
gulp.task('styles', function(){
gulp.src(paths.source.styles)
.pipe(plumber({
// plumber finds errors in stream
errorHandeler:onError }))
.pipe(sass())
// compile sass
.pipe(gulp.dest(paths.destination.styles))
.pipe(cssmin()) // min css
.pipe(rename({ // rename file to site.min.css
suffix:'.min'
}))
.pipe(gulp.dest(paths.destination.styles))
.pipe(browserSync.stream());
});
Here's the what I am getting in terminal.. Error in plugin 'gulp-sass' Message: src/scss/partials/home/_header.scss 16:18 style declaration must contain a value
@kapena I don't get what you were expecting? You got error in terminal as was expected.. To display error notification in the tray and beep you have to install gulp-notify and beepbeep plugins as well. With following settings gulp should continue watching for changes and process tasks even after fail.
There a lot of instructions on the web regarding how to extend errorHandler method to beep and show notification on error, but all those methods breaks the basic idea of plumber: tiny and informative error message.
Take a look to difference between default error message![great_error_msg](https://cloud.githubusercontent.com/assets/1753208/9899444/8885ae52-5c62-11e5-81ac-8c843029e0e8.png)
and error message that usually comes with extended errorHandler method![poor_error_msg](https://cloud.githubusercontent.com/assets/1753208/9899452/94749854-5c62-11e5-8b8c-4e220e0392b2.png)
One of extended errorHandler implementation
Default error message shows the most important information, like path to file, line, error message, even sample of code from that line. While extended message is much worse, it shows only error message without additional information.
On the other hand it's not convenient to code without notification in case of error. In my case console is almost always hidden so I can not notice if it crashes.
As I said, there are many attempts on the web to solve this problem, but they all are not good enough.
I would be very grateful to you if you've added the ability to beep and display notification on error by default. Or at least show us how to extend the errorHandler method to make it display error messages in console such informative and beautifully as it is by defalt