{"action":"closed","issue":{"url":"https://api.github.com/repos/punkave/apostrophe-pieces-submit-widgets/issues/2","repository_url":"https://api.github.com/repos/punkave/apostrophe-pieces-submit-widgets","labels_url":"https://api.github.com/repos/punkave/apostrophe-pieces-submit-widgets/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/punkave/apostrophe-pieces-submit-widgets/issues/2/comments","events_url":"https://api.github.com/repos/punkave/apostrophe-pieces-submit-widgets/issues/2/events","html_url":"https://github.com/punkave/apostrophe-pieces-submit-widgets/issues/2","id":189240752,"number":2,"title":"beforeInsert hook does not obey node callback convention, needs fix ASAP","user":{"login":"boutell","id":32125,"avatar_url":"https://avatars.githubusercontent.com/u/32125?v=3","gravatar_id":"","url":"https://api.github.com/users/boutell","html_url":"https://github.com/boutell","followers_url":"https://api.github.com/users/boutell/followers","following_url":"https://api.github.com/users/boutell/following{/other_user}","gists_url":"https://api.github.com/users/boutell/gists{/gist_id}","starred_url":"https://api.github.com/users/boutell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boutell/subscriptions","organizations_url":"https://api.github.com/users/boutell/orgs","repos_url":"https://api.github.com/users/boutell/repos","events_url":"https://api.github.com/users/boutell/events{/privacy}","received_events_url":"https://api.github.com/users/boutell/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"colpanik","id":1735569,"avatar_url":"https://avatars.githubusercontent.com/u/1735569?v=3","gravatar_id":"","url":"https://api.github.com/users/colpanik","html_url":"https://github.com/colpanik","followers_url":"https://api.github.com/users/colpanik/followers","following_url":"https://api.github.com/users/colpanik/following{/other_user}","gists_url":"https://api.github.com/users/colpanik/gists{/gist_id}","starred_url":"https://api.github.com/users/colpanik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colpanik/subscriptions","organizations_url":"https://api.github.com/users/colpanik/orgs","repos_url":"https://api.github.com/users/colpanik/repos","events_url":"https://api.github.com/users/colpanik/events{/privacy}","received_events_url":"https://api.github.com/users/colpanik/received_events","type":"User","site_admin":false},"assignees":[{"login":"colpanik","id":1735569,"avatar_url":"https://avatars.githubusercontent.com/u/1735569?v=3","gravatar_id":"","url":"https://api.github.com/users/colpanik","html_url":"https://github.com/colpanik","followers_url":"https://api.github.com/users/colpanik/followers","following_url":"https://api.github.com/users/colpanik/following{/other_user}","gists_url":"https://api.github.com/users/colpanik/gists{/gist_id}","starred_url":"https://api.github.com/users/colpanik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colpanik/subscriptions","organizations_url":"https://api.github.com/users/colpanik/orgs","repos_url":"https://api.github.com/users/colpanik/repos","events_url":"https://api.github.com/users/colpanik/events{/privacy}","received_events_url":"https://api.github.com/users/colpanik/received_events","type":"User","site_admin":false},{"login":"austinstarin","id":4621109,"avatar_url":"https://avatars.githubusercontent.com/u/4621109?v=3","gravatar_id":"","url":"https://api.github.com/users/austinstarin","html_url":"https://github.com/austinstarin","followers_url":"https://api.github.com/users/austinstarin/followers","following_url":"https://api.github.com/users/austinstarin/following{/other_user}","gists_url":"https://api.github.com/users/austinstarin/gists{/gist_id}","starred_url":"https://api.github.com/users/austinstarin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/austinstarin/subscriptions","organizations_url":"https://api.github.com/users/austinstarin/orgs","repos_url":"https://api.github.com/users/austinstarin/repos","events_url":"https://api.github.com/users/austinstarin/events{/privacy}","received_events_url":"https://api.github.com/users/austinstarin/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2016-11-14T22:09:54Z","updated_at":"2016-11-16T18:49:14Z","closed_at":"2016-11-16T18:49:14Z","body":"This code does not follow the node convention for callbacks.\r\n\r\nThis is the strongest convention in node, really the only hard and fast rule in node. So this needs to be fixed.\r\n\r\nThe first argument to the callback invoked by beforeInsert MUST be err (which would be `null` if there is no error). All callbacks in node are written to expect this and the first thing they do is check that argument.\r\n\r\nAdditional arguments are allowed, but only make sense if there is something new the callback won't have access to otherwise. And that is not the case here.\r\n\r\nSo this default implementation you wrote should look like:\r\n\r\n```\r\nself.beforeInsert = function(req, piece, callback) {\r\n   return callback(null);\r\n};\r\n```\r\n\r\nAnd the code that calls it needs to look like:\r\n\r\n```\r\nreturn self.beforeInsert(req, piece, function(err) {\r\n  // Things go wrong, pay attention to that!\r\n  if (err) {\r\n    return callback(err);\r\n  }\r\n  // We already had req and piece and we don't need them passed to us again.\r\n  return self.pieces.insert(req, piece, { permissions: false }, callback);\r\n});   \r\n```\r\n\r\nAnd any overrides need to be fixed ASAP too.\r\n\r\nSorry to be a pain!\r\n\r\n"}}
{"actor":{"display_login":"boutell"}}