{"action":"created","issue":{"url":"https://api.github.com/repos/adametry/gulp-eslint/issues/135","repository_url":"https://api.github.com/repos/adametry/gulp-eslint","labels_url":"https://api.github.com/repos/adametry/gulp-eslint/issues/135/labels{/name}","comments_url":"https://api.github.com/repos/adametry/gulp-eslint/issues/135/comments","events_url":"https://api.github.com/repos/adametry/gulp-eslint/issues/135/events","html_url":"https://github.com/adametry/gulp-eslint/issues/135","id":131440230,"number":135,"title":"Error handling - no output from .on('error')","user":{"login":"rosskevin","id":136564,"avatar_url":"https://avatars.githubusercontent.com/u/136564?v=3","gravatar_id":"","url":"https://api.github.com/users/rosskevin","html_url":"https://github.com/rosskevin","followers_url":"https://api.github.com/users/rosskevin/followers","following_url":"https://api.github.com/users/rosskevin/following{/other_user}","gists_url":"https://api.github.com/users/rosskevin/gists{/gist_id}","starred_url":"https://api.github.com/users/rosskevin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rosskevin/subscriptions","organizations_url":"https://api.github.com/users/rosskevin/orgs","repos_url":"https://api.github.com/users/rosskevin/repos","events_url":"https://api.github.com/users/rosskevin/events{/privacy}","received_events_url":"https://api.github.com/users/rosskevin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-02-04T18:46:24Z","updated_at":"2016-02-05T21:14:51Z","closed_at":null,"body":"I would like to plugin my custom error handling/notifier.  In my other recipes such as [sass](https://github.com/alienfast/gulp-pipeline/blob/master/src/sass.js#L59), I simply use:\r\n```javascript\r\n.on('error', (error) => {\r\n    this.notifyError(error, watching)\r\n})\r\n```\r\nI see this plugin uses `throw Error` instead of a  `stream.emit('error')` [similar to scssLint](https://github.com/juanfran/gulp-scss-lint/blob/master/src/index.js#L36)\r\n\r\nIn order to work around this issue where `#failAfterError` doesn't emit an error to my handler, I [implemented a very ugly `#result` handler](https://github.com/alienfast/gulp-pipeline/blob/master/src/eslint.js#L56) mostly duplicating `#failAfterError` but it will trigger my own notifier (`#results` fails to notify).  \r\n\r\nNote: this custom error handling attempts led me to discover to #134 \r\n\r\nI'm new to gulp, but it seems like I should be able to listen for an error based on patterns of use from other plugins.  Is there any recommendation to improve [this code](https://github.com/alienfast/gulp-pipeline/blob/master/src/eslint.js#L56)?  It seems like an unnecessary hack.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/adametry/gulp-eslint/issues/comments/180555978","html_url":"https://github.com/adametry/gulp-eslint/issues/135#issuecomment-180555978","issue_url":"https://api.github.com/repos/adametry/gulp-eslint/issues/135","id":180555978,"user":{"login":"adametry","id":2266622,"avatar_url":"https://avatars.githubusercontent.com/u/2266622?v=3","gravatar_id":"","url":"https://api.github.com/users/adametry","html_url":"https://github.com/adametry","followers_url":"https://api.github.com/users/adametry/followers","following_url":"https://api.github.com/users/adametry/following{/other_user}","gists_url":"https://api.github.com/users/adametry/gists{/gist_id}","starred_url":"https://api.github.com/users/adametry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adametry/subscriptions","organizations_url":"https://api.github.com/users/adametry/orgs","repos_url":"https://api.github.com/users/adametry/repos","events_url":"https://api.github.com/users/adametry/events{/privacy}","received_events_url":"https://api.github.com/users/adametry/received_events","type":"User","site_admin":false},"created_at":"2016-02-05T21:14:51Z","updated_at":"2016-02-05T21:14:51Z","body":"Indeed, `failAfterError` must \"finish\" (input closed event) and/or \"end\" (output closed event) before gulp will consider it done. For clarity, all files may pass through one or all streams in a pipeline before any stream ends.\r\n\r\nHow it works: `failAfterError` creates a pass-through stream that collects the sum of ESLint result errors. After the last file passes through, the writable (input) side of the stream will be closed (by whatever is piping into it). It's just before the \"finish\" event that `failAfterError` will throw (+ emit) an error if the error sum is greater than zero. This means that the error occurs after the last file has passed through, but before the `failAfterError` stream has emitted a \"finish\" or \"end\" event (ending the gulp task).\r\n\r\nCan you place the following modified `failAfterError` method in place of `eslint.failAfterError()` in either example?\r\n```javascript\r\n\teslint.results(function(results) {\r\n\t\tvar count = results.errorCount;\r\n\t\tconsole.log('Total ESLint Error Count: ' + count);\r\n\t\tif (count > 0) {\r\n\t\t\tthrow new Error('Failed with Errors');\r\n\t\t}\r\n\t})\r\n\t.on('error', function(error) {\r\n\t\tconsole.log('Total ESLint Error Count: ' + error);\r\n\t})\r\n\t.on('finish', function() {\r\n\t\tconsole.log('eslint.results finished');\r\n\t})\r\n\t.on('end', function() {\r\n\t\tconsole.log('eslint.results ended');\r\n\t});\r\n```\r\nThe console output should shed a bit of light on when the stream is closing and why there's no error."}}