Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better errors than badarg #58

Open
eproxus opened this issue Jun 3, 2021 · 3 comments
Open

Better errors than badarg #58

eproxus opened this issue Jun 3, 2021 · 3 comments

Comments

@eproxus
Copy link

eproxus commented Jun 3, 2021

Is there any plan to add better errors than just badarg? It's problematic when trying to encode/decode inside more complex code:

    try
        complex_code(Binary) % Code that calls jsone:decode somewhere
    catch
        error:badarg:ST ->
            case ST of
                [{jsone_decode,_,_,_}|_] ->
                        ?LOG_WARNING("Bad JSON: ~p", [Binary]);
                _ ->
                    erlang:raise(error, badarg, ST)
            end
    end.

It's impossible to know where the badarg error comes from without checking the stack trace.

I apologize if this have been considered already, since there might be a lot of code changes / possible overhead (e.g. if try-catch is used).

@sile
Copy link
Owner

sile commented Jun 13, 2021

Sorry for the late reply.
Currently, there is no plan to improve the error handling code. However, I think that it's great to make it better if it's possible to do that without performance overhead.
Unfortunately, I have no time to try that. But feel free to put a PR if you're interested in it.

@eproxus
Copy link
Author

eproxus commented Jun 14, 2021

@sile I'd be happy to create a PR. After some initial research it seems that replacing the exception defined here should do the trick: https://github.com/sile/jsone/blob/master/src/jsone_decode.erl#L42

Can you confirm?

@sile
Copy link
Owner

sile commented Jun 14, 2021

Thanks for your investigation.
It sound good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants