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

Wrong error message for binary_to_existing_atom/2 #4900

Closed
josevalim opened this issue May 27, 2021 · 0 comments · Fixed by #4901
Closed

Wrong error message for binary_to_existing_atom/2 #4900

josevalim opened this issue May 27, 2021 · 0 comments · Fixed by #4901
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@josevalim
Copy link
Contributor

Describe the bug

If you give an ASCII binary to binary_to_existing_atom/1 and binary_to_existing_atom/2, which is not an existing atom, it raises as expected, but the error message says it says the error is caused by the utf8 encoding, which is wrong.

To Reproduce

3> binary_to_existing_atom(<<"oops doesnt_really_exist">>, utf8).
** exception error: bad argument
     in function  binary_to_existing_atom/2
        called as binary_to_existing_atom(<<"oops doesnt_really_exist">>,utf8)
        *** argument 1: invalid UTF8 encoding

Expected behavior

Probably to show the same error message as list_to_existing_atom/1:

7> list_to_existing_atom("oops doesnt_really_exist").
** exception error: bad argument
     in function  list_to_existing_atom/1
        called as list_to_existing_atom("oops doesnt_really_exist")
        *** argument 1: not an already existing atom

However, note that giving a non-list argument to list_to_existing_atom/1 shows a wrong error message too:

8> list_to_existing_atom(1).
** exception error: bad argument
     in function  list_to_existing_atom/1
        called as list_to_existing_atom(1)
        *** argument 1: not an already existing atom

It should say it is not a list instead.

Affected versions

OTP 24.

@josevalim josevalim added the bug Issue is reported as a bug label May 27, 2021
@bjorng bjorng added the team:VM Assigned to OTP team VM label May 27, 2021
@bjorng bjorng self-assigned this May 27, 2021
bjorng added a commit to bjorng/otp that referenced this issue May 27, 2021
The extended error information binary_to_existing_atom/2 when the encoding
was `utf8` or `unicode`:

    1> binary_to_existing_atom(<<"oops doesnt_really_exist">>, utf8).
    ** exception error: bad argument
         in function  binary_to_existing_atom/2
            called as binary_to_existing_atom(<<"oops doesnt_really_exist">>,utf8)
            *** argument 1: invalid UTF8 encoding

Corrected:

    1> binary_to_existing_atom(<<"oops doesnt_really_exist">>, utf8).
    ** exception error: bad argument
         in function  binary_to_existing_atom/2
            called as binary_to_existing_atom(<<"oops doesnt_really_exist">>,utf8)
            *** argument 1: not an already existing atom

Closes erlang#4900.
bjorng added a commit to bjorng/otp that referenced this issue May 27, 2021
The extended error information for binary_to_existing_atom/2 was wrong
when the encoding was `utf8` or `unicode`:

    1> binary_to_existing_atom(<<"oops doesnt_really_exist">>, utf8).
    ** exception error: bad argument
         in function  binary_to_existing_atom/2
            called as binary_to_existing_atom(<<"oops doesnt_really_exist">>,utf8)
            *** argument 1: invalid UTF8 encoding

Corrected:

    1> binary_to_existing_atom(<<"oops doesnt_really_exist">>, utf8).
    ** exception error: bad argument
         in function  binary_to_existing_atom/2
            called as binary_to_existing_atom(<<"oops doesnt_really_exist">>,utf8)
            *** argument 1: not an already existing atom

Closes erlang#4900.
bjorng added a commit to bjorng/otp that referenced this issue May 27, 2021
The extended error information for `binary_to_existing_atom/2` was wrong
when the encoding was `utf8` or `unicode`:

    1> binary_to_existing_atom(<<"oops doesnt_really_exist">>, utf8).
    ** exception error: bad argument
         in function  binary_to_existing_atom/2
            called as binary_to_existing_atom(<<"oops doesnt_really_exist">>,utf8)
            *** argument 1: invalid UTF8 encoding

Corrected:

    1> binary_to_existing_atom(<<"oops doesnt_really_exist">>, utf8).
    ** exception error: bad argument
         in function  binary_to_existing_atom/2
            called as binary_to_existing_atom(<<"oops doesnt_really_exist">>,utf8)
            *** argument 1: not an already existing atom

Closes erlang#4900.
@bjorng bjorng linked a pull request May 27, 2021 that will close this issue
bjorng added a commit to bjorng/otp that referenced this issue May 27, 2021
The extended error information for `binary_to_existing_atom/2` was wrong
when the encoding was `utf8` or `unicode`:

    1> binary_to_existing_atom(<<"oops doesnt_really_exist">>, utf8).
    ** exception error: bad argument
         in function  binary_to_existing_atom/2
            called as binary_to_existing_atom(<<"oops doesnt_really_exist">>,utf8)
            *** argument 1: invalid UTF8 encoding

Corrected:

    1> binary_to_existing_atom(<<"oops doesnt_really_exist">>, utf8).
    ** exception error: bad argument
         in function  binary_to_existing_atom/2
            called as binary_to_existing_atom(<<"oops doesnt_really_exist">>,utf8)
            *** argument 1: not an already existing atom

Also fix a similar problem for list_to_existing_atom/1.

Closes erlang#4900.
bjorng added a commit that referenced this issue May 28, 2021
…-17449

Correct error message for binary_to_existing_atom/2
@bjorng bjorng closed this as completed in c1942e3 May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants