{"action":"created","issue":{"url":"https://api.github.com/repos/fritx/gulp-edit/issues/1","labels_url":"https://api.github.com/repos/fritx/gulp-edit/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/fritx/gulp-edit/issues/1/comments","events_url":"https://api.github.com/repos/fritx/gulp-edit/issues/1/events","html_url":"https://github.com/fritx/gulp-edit/issues/1","id":53205286,"number":1,"title":"Proposal for simpler API","user":{"login":"simevidas","id":716405,"avatar_url":"https://avatars.githubusercontent.com/u/716405?v=3","gravatar_id":"","url":"https://api.github.com/users/simevidas","html_url":"https://github.com/simevidas","followers_url":"https://api.github.com/users/simevidas/followers","following_url":"https://api.github.com/users/simevidas/following{/other_user}","gists_url":"https://api.github.com/users/simevidas/gists{/gist_id}","starred_url":"https://api.github.com/users/simevidas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simevidas/subscriptions","organizations_url":"https://api.github.com/users/simevidas/orgs","repos_url":"https://api.github.com/users/simevidas/repos","events_url":"https://api.github.com/users/simevidas/events{/privacy}","received_events_url":"https://api.github.com/users/simevidas/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2014-12-31T21:54:27Z","updated_at":"2015-01-07T03:31:10Z","closed_at":null,"body":"Your API passes both the `src` and `cb` arguments to the modifier function. I think, this can be simplified. Here’s my suggestion:\r\n\r\n * only pass `src` to the modifier function (the file contents) \r\n * the modifier function returns the modified file contents or explicitly throws an error\r\n\r\nSo, instead of this:\r\n```js\r\ngulp.src('./*.txt')\r\n    .pipe(edit(function (src, cb) {\r\n        var err = null;\r\n\r\n        src += '- modified!';\r\n\r\n        if (/* something went wrong */) {\r\n            err = new Error(/* explain what went wrong */);\r\n        } \r\n\r\n        cb(err, src);\r\n    }))\r\n    .pipe(gulp.dest('./'))\r\n```\r\n\r\nI propose this:\r\n\r\n```js\r\ngulp.src('./*.txt')\r\n    .pipe(edit(function (src) {\r\n        src += '- modified!';\r\n \r\n        if (/* something went wrong */) {\r\n            throw new Error(/* explain what went wrong */);\r\n        } \r\n\r\n        return src;\r\n    }))\r\n    .pipe(gulp.dest('./'))\r\n```\r\n\r\nI think, this API is more straight-forward, since the modifier function both receives and returns a string value, and the users of your Gulp plugin don’t have to understand that `cb` pattern, but instead just throw errors when needed.\r\n\r\n**I can make a PR with this change**. Tell me what you think.\r\n\r\nPlease note that if you don’t like this API change, I intend to fork your repo and implement the change in my fork instead ^_^"},"comment":{"url":"https://api.github.com/repos/fritx/gulp-edit/issues/comments/68974493","html_url":"https://github.com/fritx/gulp-edit/issues/1#issuecomment-68974493","issue_url":"https://api.github.com/repos/fritx/gulp-edit/issues/1","id":68974493,"user":{"login":"fritx","id":6647633,"avatar_url":"https://avatars.githubusercontent.com/u/6647633?v=3","gravatar_id":"","url":"https://api.github.com/users/fritx","html_url":"https://github.com/fritx","followers_url":"https://api.github.com/users/fritx/followers","following_url":"https://api.github.com/users/fritx/following{/other_user}","gists_url":"https://api.github.com/users/fritx/gists{/gist_id}","starred_url":"https://api.github.com/users/fritx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fritx/subscriptions","organizations_url":"https://api.github.com/users/fritx/orgs","repos_url":"https://api.github.com/users/fritx/repos","events_url":"https://api.github.com/users/fritx/events{/privacy}","received_events_url":"https://api.github.com/users/fritx/received_events","type":"User","site_admin":false},"created_at":"2015-01-07T03:31:10Z","updated_at":"2015-01-07T03:31:10Z","body":"It's weird.. I don't know either why `throw` in sync mode behaves inconsistently with async mode, though they both go through `cb` in `retFn`.\r\nBut I found another plugin `gulp-notify`, and it works consistently for both\r\n\r\n```js\r\n.pipe(edit(function(){/**/}))\r\n.on('error', notify.onError(function (err) {\r\n  return 'Message to the notifier: ' + err.message;\r\n}))\r\n.pipe(gulp.dest('playground/dest/'));\r\n```"}}