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

Raise ArgumentError in Keyword.keys when list is not a keyword list #10214

Merged

Conversation

eksperimental
Copy link
Contributor

Previously it would return something like this:

** (FunctionClauseError) no function clause matching in anonymous fn/1 in Keyword.keys/1

The following arguments were given to anonymous fn/1 in Keyword.keys/1:

    # 1
    {"fetch/2", {:fetch, 2}}

Closes #10010, and it improves 3fd68ef

Previously it would return something like this:

** (FunctionClauseError) no function clause matching in anonymous fn/1 in Keyword.keys/1

    The following arguments were given to anonymous fn/1 in Keyword.keys/1:

        # 1
        {"fetch/2", {:fetch, 2}}

Closes elixir-lang#10010, and it improves 3fd68ef
Comment on lines 451 to 453
"expected a keyword list, but an element in the list is not a keyword; got: #{
inspect(element)
}"
Copy link
Member

@josevalim josevalim Jul 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"expected a keyword list, but an element in the list is not a keyword; got: #{
inspect(element)
}"
"expected a keyword list, but an element in the list is not a two-element tuple with atom key, " <>
"got: #{inspect(element)}"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement your suggestion with the addition of the article "an".

I am not 100% sure on the accuracy of the message though, as tuples don't have keys.
How about something like this?

expected a keyword list, but an element in the list is not a two-element tuple with its first element being an atom; got:

@michalmuskala
Copy link
Member

Raising deep from within the map call might result in a pretty poor error message with the whole printable stacktrace being only the map calls. I would suggest throwing from within the map, catching outside and re-raising with a stacktrace of the Keyword.keys/1 directly

@eksperimental eksperimental force-pushed the keyword_keys_exception branch 3 times, most recently from f5aeb9e to 272e1a2 Compare July 21, 2020 05:29
@josevalim josevalim merged commit 5834b14 into elixir-lang:master Jul 21, 2020
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@eksperimental eksperimental deleted the keyword_keys_exception branch July 21, 2020 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Keyword.keys/1 accepts non-keyword lists and returns their keys
3 participants