I’m trying to fetch the documentation of a module right after it is compiled, in order to process it. I use the following code to check if the module was compiled. Even though I check if the function whose docs I’m searching exists, I get an error-status when I call Code.fetch_docs/1
.
Are there any additional checks I should perform?
if command_compiled?(module, function, arity) do
docs = fetch_docs(module, function, arity)
# process docs
else
IO.warn("#{scope.module}.#{function}/#{arity} does not exist")
nil
end
# Helper functions
defp command_compiled?(module, name, arity) do
case Code.ensure_compiled(module) do
{:module, ^module} -> function_exported?(module, name, arity)
_ -> false
end
end
defp fetch_docs(module, function, arity) do
{_, _, _, _, _, _, functions} = Code.fetch_docs(module) # {:error, :module_not_found}
matcher = fn
{{:function, ^function, ^arity}, _, _, %{"en" => docs}, _} -> docs
_ -> nil
end
Enum.find_value(functions, matcher)
end