Reputation: 1892
Does anyone have any idea how you would handle errors in gulp-ruby-sass. I have noticed that it outputs directly to console when there is an error, but I would like to handle it myself.
gulp.task('styles', function () {
return gulp.src(sources.sass.files)
.pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
.pipe(
plugins.rubySass({
lineNumbers: true,
style: 'expanded',
sourcemap: true,
sourcemapPath: '../../dev/sass'
})
)
.on("error", function(err) {
console.log(err);
})
.pipe(gulp.dest(sources.sass.dest));
});
As you can see, I am trying two different ways to handle my error here but neither of them work. If I try .on("error", console.log('error'))
that works, but it tells me the 'listener must be a function'.
Thanks in advance.
Upvotes: 0
Views: 748
Reputation: 1633
You can also use a package I published, pipe-error-stop
as follows:
pipeErrorStop = require('pipe-error-stop');
// in the task
.pipe(pipeErrorStop(rubySass()))
If rubySass
emits an error, no data will be passed onward further down the pipe. This prevents you from making a syntax error in your sass and finding a stack trace on your home page.
pipeErrorStop
has callbacks that you can use to hook into, as well.
Upvotes: 1
Reputation: 1892
https://github.com/mikaelbr/gulp-notify/issues/37#issuecomment-48457930
Issue has been fixed by another GitHub user.
Upvotes: 0
Reputation: 2083
Using gulp-plumber
might help you, have a look at this blogpost !
It would allow you do:
var onError = function (err) {
// whatever you need to do
};
gulp.task('styles', function () {
gulp.src('scss/style.scss')
.pipe(plumber({
errorHandler: onError
}))
.pipe(rubysass())
.pipe(gulp.dest('dist/'));
});
Upvotes: 0