Skip to content

Conversation

eksperimental
Copy link
Contributor

I was getting a really long cyptic message showing the whole list of docs, but for a private function,

** (FunctionClauseError) no function clause matching in Code.do_lookup_docs/2
    (elixir) lib/code.ex:634: Code.do_lookup_docs([docs: [{{:%, 2}, 105, :defmacro, [{:struct, [], nil}, {:map, [], nil}], "Creates a struct.\n\nA struct is a tagged map that allows developers to provide\ndefault values for keys, tags to be used in polymorphic\ndispatches and compile time assertions.\n\nTo define a 

It also add :all as the default value for kind

defp do_lookup_docs(docs, :all), do: docs
defp do_lookup_docs(docs, kind) when kind in @doc_sections,
defp do_lookup_docs(docs, kind) when kind in @doc_kinds,
Copy link
Member

Choose a reason for hiding this comment

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

If kind in @doc_kinds moves to get_docs there is no need to have it here, but you need to add it to the second get_docs definition as well. I think it probably doesn't worth it to move it then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooops....
fixed! thanks for your comments (as usual),
I have created a function head, and removed the check in the private functions.
Well, we do need to update it, because this is the full error I was getting: https://gist.github.com/eksperimental/399036a2ccb27fe198e5

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, now it'll look better.

@doc_kinds [:docs, :moduledoc, :callback_docs, :type_docs]
def get_docs(module, kind \\ :all)

def get_docs(module, kind) when is_atom(module) and kind in @doc_kinds or kind == :all do
Copy link
Member

Choose a reason for hiding this comment

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

I think parenthesis around kind checks will improve readability.

Copy link
Member

Choose a reason for hiding this comment

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

Add :all to @doc_kinds and skip the extra check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. now that we removed the checked in the private function we can do it.

@lexmag
Copy link
Member

lexmag commented Sep 17, 2015

I'm afraid that default value for king will turn the usage of this function into: Code.get_docs(mod)[kind], which returns nil values in case of typo, for example. I think be explicit in this case is much better. (\cc @josevalim)

@josevalim
Copy link
Member

Exactly, let's please remove the default value.

@eksperimental
Copy link
Contributor Author

yes. that was a really good point @lexmag

…private

This was giving me a long cryptic message because we were checking for a valid kind
way to far.

I have renamed the attribute to @doc_kinds instead of @doc_sections

Corrected kinds for :all option

Mention that no valid module returns nil, and created a doctest example.
@eksperimental
Copy link
Contributor Author

done. I don't see the travis build status for this

josevalim added a commit that referenced this pull request Sep 17, 2015
Code.get_docs/2: check for valid kinds in public function
@josevalim josevalim merged commit 3b323e1 into elixir-lang:master Sep 17, 2015
@eksperimental eksperimental deleted the get_docs branch September 30, 2015 03:17
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.

4 participants