Search code examples
error-handlinggulpbrowser-syncgulp-notify

Error handling with gulp-ruby-sass 1.0.0-alpha, gulp-notify, and browser-sync


I've been using `[email protected]' because < 1.0 doesn't play well with Sass >= 3.4 According to the documentation:

gulp-ruby-sass throws errors like a gulp plugin, but streams the erroring files so you can see the errors in your browser.

I use gulp-notify to handle errors with this code that gives me a popup notification that lets me know that something went wrong.

.on('error', notify.onError({
    title: 'Error!',
    message: '<%= error.message %>',
    sound: 'Beep'
}))

This works as-is for my other tasks (in my 'scripts' task I need to specify the gulp-jshint fail reporter). But in my 'styles' task the error message is being streamed to the console and the browser but not to a popup notification.

It's workable as is, but when using browser-sync for css style injection, the error message can be missed. Sometimes I'm not working at the top of the document where it renders the error message.

Ideally, I would like to receive a notification that can prompt me to check for errors. Does anyone know why I can't create a message with gulp-notify?


Solution

  • The solution I found was to wrap notify.onError in an anonymous function and append this.emit('end'):

    .on('error', function(err) {
        notify.onError({
            title: 'Error!',
            message: '<%= error.message %>',
            sound: 'Beep'
        })(err);
        this.emit('end');
    })