{"action":"created","issue":{"url":"https://api.github.com/repos/mikaelbr/gulp-notify/issues/81","repository_url":"https://api.github.com/repos/mikaelbr/gulp-notify","labels_url":"https://api.github.com/repos/mikaelbr/gulp-notify/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/mikaelbr/gulp-notify/issues/81/comments","events_url":"https://api.github.com/repos/mikaelbr/gulp-notify/issues/81/events","html_url":"https://github.com/mikaelbr/gulp-notify/issues/81","id":72363859,"number":81,"title":"Making notifications, error logging, and watchers play nicely","user":{"login":"brendanfalkowski","id":214924,"avatar_url":"https://avatars.githubusercontent.com/u/214924?v=3","gravatar_id":"","url":"https://api.github.com/users/brendanfalkowski","html_url":"https://github.com/brendanfalkowski","followers_url":"https://api.github.com/users/brendanfalkowski/followers","following_url":"https://api.github.com/users/brendanfalkowski/following{/other_user}","gists_url":"https://api.github.com/users/brendanfalkowski/gists{/gist_id}","starred_url":"https://api.github.com/users/brendanfalkowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendanfalkowski/subscriptions","organizations_url":"https://api.github.com/users/brendanfalkowski/orgs","repos_url":"https://api.github.com/users/brendanfalkowski/repos","events_url":"https://api.github.com/users/brendanfalkowski/events{/privacy}","received_events_url":"https://api.github.com/users/brendanfalkowski/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-05-01T06:06:24Z","updated_at":"2016-02-11T18:49:04Z","closed_at":"2015-05-09T04:00:54Z","body":"I've been banging my head to get `gulp-notify`, `gulp-plumber`, and `gulp-sass` working for a few hours. The build works fine, but I'm struggling to get error notifications to play nice. What I want is:\r\n\r\n1. OS notification that an error occurred\r\n1. Error reported in the console\r\n1. Watch task does **not** stop\r\n\r\nIt feels like none of the modules want this to happen.\r\n\r\n## First Attempt\r\n\r\nI tried these `.onError` commands directly in the task stream, but that stops the watcher:\r\n\r\n```javascript\r\ngulp.task('css', function () {\r\n    return gulp.src('scss/**/*.scss')\r\n    .pipe(sass())\r\n\r\n    // First try\r\n    .on('error', function () {\r\n        notify({\r\n            title: 'Gulp: CSS',\r\n            message: 'Error'\r\n        })\r\n    })\r\n\r\n    // Second try\r\n    .on('error', notify.onError({\r\n        title: 'Gulp: CSS',\r\n        message: 'Error'\r\n    }))\r\n\r\n    // Third try\r\n    .on('error', function (err) {\r\n        return notify().write({\r\n            title: 'Gulp: CSS',\r\n            message: 'Error'\r\n        });\r\n    })\r\n});\r\n```\r\n\r\nNote: I found all these different syntaxes in gulpfiles from others, but with no real explanations of why they should be used.\r\n\r\n## Second Attempt\r\n\r\nThen I tried using `gulp-sass` callback for `onError`:\r\n\r\n```javascript\r\ngulp.task('css', function () {\r\n    return gulp.src('scss/**/*.scss')\r\n    .pipe(sass({\r\n        errLogToConsole: false,\r\n        onError: notify.onError({\r\n            title: 'Gulp: CSS',\r\n            message: 'Error'\r\n        })\r\n    }))\r\n});\r\n```\r\n\r\nBut setting `errLogToConsole: false` means you can't see the error. Changing to `true` means the watcher stops.\r\n\r\n## Third Attempt\r\n\r\nThen I tried I'm using `gulp-plumber` so the watcher doesn't stop.\r\n\r\n```javascript\r\ngulp.task('css', function () {\r\n    return gulp.src('scss/**/*.scss')\r\n    .pipe(plumber({\r\n        errorHandler: reportError\r\n    }))\r\n    .pipe(sass())\r\n    .on('error', reportError)\r\n});\r\n```\r\n\r\nWith the error handling function:\r\n\r\n```javascript\r\nfunction reportError (error) {\r\n    notify().write({\r\n        title: 'Gulp: CSS',\r\n        message: 'Error'\r\n    });\r\n\r\n    console.log(error.toString());\r\n}\r\n```\r\n\r\nThis sort of works, but `notify.write()` ignores the `title` property passed in. I couldn't find any docs for this.\r\n\r\nThe watcher breaks but doesn't stop. Correcting the CSS error and saving has no effect.\r\n\r\nEven if that did work, the error handler would be hardcoded for the CSS task. I'm trying to re-use this for JS too.\r\n\r\n## Fourth Attempt\r\n\r\nThen I tried to rewrite the second attempt to be self-contained and not rely on `gulp-plumber` with an anonymous function for error reporting + notification:\r\n\r\n```javascript\r\ngulp.task('css', function () {\r\n    return gulp.src('scss/**/*.scss')\r\n    .pipe(sass({\r\n        errLogToConsole: false,\r\n        onError: function (err) {\r\n            console.log(err);        \r\n            notify().write({\r\n                title: 'Gulp: CSS',\r\n                message: 'Error'\r\n            });\r\n        }\r\n    }))\r\n});\r\n```\r\n\r\nThis technically does all three things I want:\r\n\r\n1. OS notification that an error occurred (but not nicely formatted)\r\n1. Error reported in the console\r\n1. Watch task does **not** to stop (and stays functional)\r\n\r\nBut it means I need another workaround for JS (or other tasks that may need error handling).\r\n\r\n## What am I missing here?\r\n\r\nThere has to be a better way."},"comment":{"url":"https://api.github.com/repos/mikaelbr/gulp-notify/issues/comments/183007576","html_url":"https://github.com/mikaelbr/gulp-notify/issues/81#issuecomment-183007576","issue_url":"https://api.github.com/repos/mikaelbr/gulp-notify/issues/81","id":183007576,"user":{"login":"colorful-tones","id":405912,"avatar_url":"https://avatars.githubusercontent.com/u/405912?v=3","gravatar_id":"","url":"https://api.github.com/users/colorful-tones","html_url":"https://github.com/colorful-tones","followers_url":"https://api.github.com/users/colorful-tones/followers","following_url":"https://api.github.com/users/colorful-tones/following{/other_user}","gists_url":"https://api.github.com/users/colorful-tones/gists{/gist_id}","starred_url":"https://api.github.com/users/colorful-tones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colorful-tones/subscriptions","organizations_url":"https://api.github.com/users/colorful-tones/orgs","repos_url":"https://api.github.com/users/colorful-tones/repos","events_url":"https://api.github.com/users/colorful-tones/events{/privacy}","received_events_url":"https://api.github.com/users/colorful-tones/received_events","type":"User","site_admin":false},"created_at":"2016-02-11T18:49:04Z","updated_at":"2016-02-11T18:49:04Z","body":"I'm curious what packages are involved to get this to work please? https://github.com/mikaelbr/gulp-notify/issues/81#issuecomment-100422179\r\n\r\nI'm thinking: gulp-notify, gulp-util, gulp-plumber, and anything else?"}}