Phoenix generates the following module:
defmodule IslandsInterfaceWeb.ErrorView do use IslandsInterfaceWeb, :view def template_not_found(template, _assigns) do Phoenix.Controller.status_message_from_template(template) end end
I implement Credo in my codebases and run it in strict mode. The function
template_not_found/2 fails the
Credo.Check.Readability.Specs Credo check, despite there being a typespec defined for it in the
Phoenix.Template module in
If I add any
IslandsInterfaceWeb.ErrorView.template_not_found/2, including the exact spec listed in the link above, then I get the following Dialyzer error:
Overloaded contract for IslandsInterfaceWeb.ErrorView.template_not_found/2 has
overlapping domains; such contracts are currently unsupported and
are simply ignored.
So then I thought, maybe it’s a callback. The documentation linked above does mention that it is a callback, but only in the documentation. But if I add
@impl true to
IslandsInterfaceWeb.ErrorView.template_not_found/2 with no
@spec, then I get the compiler warning:
warning: got “@impl true” for function template_not_found/2 but no behaviour was declared
Even if that worked, I enforce the
Credo.Check.Readability.ImplTrue Credo check, so I need an explicit behaviour name.
My guesses are either that:
- Credo or something it uses does not appropriately pick up the
template_not_found/2is a callback, but either the callback or behaviour is not defined properly. I’m not yet familiar enough with Phoenix, macros, or
defoverridableto be able to efficiently debug this. Perhaps this is related to the post Behaviours, defoverridable and implementations?
How do I solve this such that I can run the Credo checks, Dialyzer, and
mix compile --warnings-as-errors all successfully? At present, I am unable to do so.