OS notification in gulp-notify doesn't work

185 Views Asked by At

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?

1

There are 1 best solutions below

2
On

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());
}