0

Hi everyone

I have a custom error handler that's supposed to show a notification with gulp-notify and then log it in the console when sass compiler fail.

var errorHandler = function(error) {
    notify.onError({
        title: 'Task Failed [' + error.plugin + ']',
        message: 'Sass ha ricontrato un errore',
        sound: true
    })(error);
    this.emit('end');
    notify("Files has an error");
    return notify().write(error);
};

function scss() {
    return src("product-template/Product Template/assets/styles/scss/**/*.scss")
        .pipe(sourcemaps.init())
        .pipe(sass())
        .on("error", errorHandler)
        .pipe(prefix(/*{grid: "no-autoplace"}*/))
        .pipe(sourcemaps.write("./"))
        .pipe(dest("./product-template/Product Template/assets/styles/css/"))
        .pipe(browserSync.stream());
}

Expected behavior

This piece of code supposed to, when sass has an error, to show a notification Os (windows) message (toast) with a title, body ecc

Real behavior

The piece of code actualy doesn't work it only log the message of error in the console. Don't the expected behavior


is there any error in the configuration?

Community
  • 1
  • 1

1 Answers1

0

Try this.

function scss() {
    return src("product-template/Product Template/assets/styles/scss/**/*.scss")
        .pipe(sourcemaps.init())
        .pipe(sass())
        .on("error", function(error) {
            notify.onError({
                title: 'Task Failed [' + error.plugin + ']',
                message: 'Sass ha ricontrato un errore',
                sound: true
            })(error);
            this.emit('end');
            notify("Files has an error");
            return notify().write(error);
        })
        .pipe(prefix(/*{grid: "no-autoplace"}*/))
        .pipe(sourcemaps.write("./"))
        .pipe(dest("./product-template/Product Template/assets/styles/css/"))
        .pipe(browserSync.stream());
}
Waldir Bolanos
  • 422
  • 3
  • 7
  • I tried your answer, but nothing change. I think that the problem is in Windows, because certain times I receive the notification from gulp, and certain times nothing –  Mar 12 '20 at 13:35
  • Interesting, my answer is working correctly in my machine, but I am on a mac, it could very well be a windows issue. – Waldir Bolanos Mar 12 '20 at 15:20