{"action":"opened","issue":{"url":"https://api.github.com/repos/lordnull/rec2json/issues/21","repository_url":"https://api.github.com/repos/lordnull/rec2json","labels_url":"https://api.github.com/repos/lordnull/rec2json/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/lordnull/rec2json/issues/21/comments","events_url":"https://api.github.com/repos/lordnull/rec2json/issues/21/events","html_url":"https://github.com/lordnull/rec2json/issues/21","id":148993653,"number":21,"title":"Errors when a type mismatches on to_json are not helpful","user":{"login":"lordnull","id":89714,"avatar_url":"https://avatars.githubusercontent.com/u/89714?v=3","gravatar_id":"","url":"https://api.github.com/users/lordnull","html_url":"https://github.com/lordnull","followers_url":"https://api.github.com/users/lordnull/followers","following_url":"https://api.github.com/users/lordnull/following{/other_user}","gists_url":"https://api.github.com/users/lordnull/gists{/gist_id}","starred_url":"https://api.github.com/users/lordnull/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lordnull/subscriptions","organizations_url":"https://api.github.com/users/lordnull/orgs","repos_url":"https://api.github.com/users/lordnull/repos","events_url":"https://api.github.com/users/lordnull/events{/privacy}","received_events_url":"https://api.github.com/users/lordnull/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-17T20:33:26Z","updated_at":"2016-04-17T20:33:26Z","closed_at":null,"body":"When `rec2json` cannot convert a term to a json representation, it throws a exception of type `{badarg, field_name(), field_value(), field_types()}`. This is correct as far as adhering to erlang error output structure, but ends up writing something like the following to the console:\r\n\r\n```\r\n** exception error: bad argument: \r\n                    {products,\r\n                        [{product,undefined,undefined,undefined,undefined,\r\n                             undefined,undefined,undefined,undefined,\r\n                             undefined,undefined,undefined,undefined,\r\n                             undefined,undefined}],\r\n                        {specific,\r\n                            [undefined,\r\n                             {list,{specific,[{product,product,[]}]}}]}}\r\n     in function  rec2json:'-to_json/2-fun-1-'/3 (src/rec2json.erl, line 145)\r\n     in call from lists:foldl/3 (lists.erl, line 1262)\r\n     in call from rec2json:to_json/2 (src/rec2json.erl, line 135)\r\n```\r\n\r\nSure, if you stare at that and the rec2json source code, or you know the rec2json error format above, it's slightly helpful, otherwise it's a mismash of wtf. Often, when this happens, it is not meant to be handled and recovered, but fixed by a developer. This means developer understanding of the error is more important that efficient consumption by a computer. Given that, the format should change:\r\n\r\n```\r\nerlang:error({badarg, {error_details, #{\r\n    field_name => field_name(),\r\n    field_value => field_value(),\r\n    allow_any => boolean(),\r\n    expected_types => [field_type()]}}})\r\n```\r\n\r\nWith a completely faked error, the console output becomes:\r\n\r\n```\r\n** exception error: bad argument: \r\n                    {error_details,#{allow_any => false,\r\n                                     expected_types => [undefined],\r\n                                     field_name => name,\r\n                                     filed_value => value}}\r\n```\r\n\r\nUse of a map because it looks nicer than a prophets, though if pre-18 is required, that can be waved."}}