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

Correct extended error for binary_to_term/2 #5172

Merged

Conversation

bjorng
Copy link
Contributor

@bjorng bjorng commented Aug 31, 2021

When binary_to_term/2 failed with a badarg exception, the extended error
information would always blame the second argument even if the error was
in the first argument:

1> binary_to_term(<<"">>, []).
** exception error: bad argument
     in function  binary_to_term/2
        called as binary_to_term(<<>>,[])
        *** argument 2: invalid option in list
2> binary_to_term(<<131,100,0,10,97,95,110,101,119,95,97,116,111,109>>, [safe]).
** exception error: bad argument
     in function  binary_to_term/2
        called as binary_to_term(<<131,100,0,10,97,95,110,101,119,95,97,116,111,109>>,
                                 [safe])
        *** argument 2: invalid option in list

Correct the extended error information like this:

1> binary_to_term(<<"">>, []).
** exception error: bad argument
     in function  binary_to_term/2
        called as binary_to_term(<<>>,[])
        *** argument 1: invalid external representation of a term
2> binary_to_term(<<131,100,0,10,97,95,110,101,119,95,97,116,111,109>>, [safe]).
** exception error: bad argument
     in function  binary_to_term/2
        called as binary_to_term(<<131,100,0,10,97,95,110,101,119,95,97,116,111,109>>,
                                 [safe])
        *** argument 1: invalid or unsafe external representation of a term

Closes #5171.

When `binary_to_term/2` failed with a `badarg` exception, the extended error
information would always blame the second argument even if the error was
in the first argument:

    1> binary_to_term(<<"">>, []).
    ** exception error: bad argument
         in function  binary_to_term/2
            called as binary_to_term(<<>>,[])
            *** argument 2: invalid option in list
    2> binary_to_term(<<131,100,0,10,97,95,110,101,119,95,97,116,111,109>>, [safe]).
    ** exception error: bad argument
         in function  binary_to_term/2
            called as binary_to_term(<<131,100,0,10,97,95,110,101,119,95,97,116,111,109>>,
                                     [safe])
            *** argument 2: invalid option in list

Correct the extended error information like this:

    1> binary_to_term(<<"">>, []).
    ** exception error: bad argument
         in function  binary_to_term/2
            called as binary_to_term(<<>>,[])
            *** argument 1: invalid external representation of a term
    2> binary_to_term(<<131,100,0,10,97,95,110,101,119,95,97,116,111,109>>, [safe]).
    ** exception error: bad argument
         in function  binary_to_term/2
            called as binary_to_term(<<131,100,0,10,97,95,110,101,119,95,97,116,111,109>>,
                                     [safe])
            *** argument 1: invalid or unsafe external representation of a term

Closes erlang#5171.
@bjorng bjorng added team:VM Assigned to OTP team VM fix testing currently being tested, tag is used by OTP internal CI labels Aug 31, 2021
@bjorng bjorng self-assigned this Aug 31, 2021
@bjorng bjorng changed the base branch from master to maint August 31, 2021 05:12
@bjorng bjorng merged commit b02bb3a into erlang:maint Sep 1, 2021
@bjorng bjorng deleted the bjorn/erts/fix-error-info/GH-5171/OTP-17591 branch September 1, 2021 08:07
@nathanl
Copy link
Contributor

nathanl commented Sep 3, 2021

👏 🎉 😄 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect error message from binary_to_term/2 with safe
2 participants