{"action":"created","issue":{"url":"https://api.github.com/repos/Hammerspoon/hammerspoon/issues/477","labels_url":"https://api.github.com/repos/Hammerspoon/hammerspoon/issues/477/labels{/name}","comments_url":"https://api.github.com/repos/Hammerspoon/hammerspoon/issues/477/comments","events_url":"https://api.github.com/repos/Hammerspoon/hammerspoon/issues/477/events","html_url":"https://github.com/Hammerspoon/hammerspoon/issues/477","id":99864733,"number":477,"title":"C code and luaL_error versus showError","user":{"login":"asmagill","id":8139480,"avatar_url":"https://avatars.githubusercontent.com/u/8139480?v=3","gravatar_id":"","url":"https://api.github.com/users/asmagill","html_url":"https://github.com/asmagill","followers_url":"https://api.github.com/users/asmagill/followers","following_url":"https://api.github.com/users/asmagill/following{/other_user}","gists_url":"https://api.github.com/users/asmagill/gists{/gist_id}","starred_url":"https://api.github.com/users/asmagill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asmagill/subscriptions","organizations_url":"https://api.github.com/users/asmagill/orgs","repos_url":"https://api.github.com/users/asmagill/repos","events_url":"https://api.github.com/users/asmagill/events{/privacy}","received_events_url":"https://api.github.com/users/asmagill/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-08-09T05:06:06Z","updated_at":"2015-09-05T18:23:50Z","closed_at":null,"body":"#473 got me thinking...\r\n\r\nLet me just start by saying up front, I know I am guilty of this... maybe I'm the only one, but if not, I put this forward as a suggested best practice.  Unless the general consensus is strongly otherwise, I plan to change my habits and adjust it as I notice it in other code...\r\n\r\nWhen C code encounters an error -- say the wrong variable type is passed, or a required argument is missing, etc., then I believe we should be terminating the function/method with `return luaL_error(L, ...)`  This terminates the function/method and allows for a formatted error string with a variable number of arguments in the error.\r\n\r\nWhen a lua callback is invoked from something that C code created (timer, eventtap, etc.), it should return errors via the showError function as defined in Hammerspoon.h.  But *only* callbacks should handle errors this way.\r\n\r\nAny other method/function is invoked within the context of other lua or c code, and it is up to that code to determine if it should wrap its calls in `pcall` or `xpcall` (if lua) or lua_pcall (if c) to catch and handle errors, or let the error terminate execution of whatever is going on.\r\n\r\nAs I said, I know I'm guilty of sticking showError in in places it doesn't really belong, but I plan to stop.\r\n\r\nThoughts?  Objections?"},"comment":{"url":"https://api.github.com/repos/Hammerspoon/hammerspoon/issues/comments/137982960","html_url":"https://github.com/Hammerspoon/hammerspoon/issues/477#issuecomment-137982960","issue_url":"https://api.github.com/repos/Hammerspoon/hammerspoon/issues/477","id":137982960,"user":{"login":"asmagill","id":8139480,"avatar_url":"https://avatars.githubusercontent.com/u/8139480?v=3","gravatar_id":"","url":"https://api.github.com/users/asmagill","html_url":"https://github.com/asmagill","followers_url":"https://api.github.com/users/asmagill/followers","following_url":"https://api.github.com/users/asmagill/following{/other_user}","gists_url":"https://api.github.com/users/asmagill/gists{/gist_id}","starred_url":"https://api.github.com/users/asmagill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asmagill/subscriptions","organizations_url":"https://api.github.com/users/asmagill/orgs","repos_url":"https://api.github.com/users/asmagill/repos","events_url":"https://api.github.com/users/asmagill/events{/privacy}","received_events_url":"https://api.github.com/users/asmagill/received_events","type":"User","site_admin":false},"created_at":"2015-09-05T18:23:50Z","updated_at":"2015-09-05T18:23:50Z","body":"(I should say all color output to the console...)"}}