Skip to content

Commit

Permalink
Only check for module loaded after getting docs chunk
Browse files Browse the repository at this point in the history
Closes #1078.
  • Loading branch information
José Valim committed Aug 13, 2019
1 parent ac0f1d2 commit 24d9783
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions lib/ex_doc/retriever.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ defmodule ExDoc.Retriever do
# the module is not available or it was not compiled
# with --docs flag), we raise an exception.
defp get_module(module, config) do
unless Code.ensure_loaded?(module) do
raise Error, "module #{inspect(module)} is not defined/available"
end

if docs_chunk = docs_chunk(module) do
generate_node(module, docs_chunk, config)
else
Expand All @@ -86,25 +82,32 @@ defmodule ExDoc.Retriever do
"For earlier Elixir versions, make sure to depend on {:ex_doc, \"~> 0.18.0\"}"
end

if function_exported?(module, :__info__, 1) do
case Code.fetch_docs(module) do
{:docs_v1, _, _, _, :hidden, _, _} ->
false
case Code.fetch_docs(module) do
{:docs_v1, _, _, _, :hidden, _, _} ->
false

{:docs_v1, _, _, _, _, _, _} = docs ->
docs
{:docs_v1, _, _, _, _, _, _} = docs ->
_ = Code.ensure_loaded(module)
docs

{:error, reason} ->
raise Error,
"module #{inspect(module)} was not compiled with flag --docs: #{inspect(reason)}"
{:error, reason} ->
cond do
not Code.ensure_loaded?(module) ->
raise Error, "module #{inspect(module)} is not defined/available"

_ ->
raise Error,
"unknown format in Docs chunk. This likely means you are running on " <>
"a more recent Elixir version that is not supported by ExDoc. Please update."
end
else
false
function_exported?(module, :__info__, 1) ->
# Not an Elixir module, ignore until we have Erlang support
false

true ->
raise Error,
"module #{inspect(module)} was not compiled with flag --docs: #{inspect(reason)}"
end

_ ->
raise Error,
"unknown format in Docs chunk. This likely means you are running on " <>
"a more recent Elixir version that is not supported by ExDoc. Please update."
end
end

Expand Down

0 comments on commit 24d9783

Please sign in to comment.