I recently had a server side error because a Phoenix view module was not aliased.
file: company_admin_view.ex
def render("foo.json", %{user: user}) do
%{
...some other stuff here...
user: render_one(user, UserView, "user_admin.json"),
}
end
UserView is undefined, as I have forgotten to alias MyApp.Web.UserView. I’m guessing the compiler warned me about this at some point, but I missed it. How do I get to review all existing compiler warnings? I’ve tried mix compile --force, but this does not mention anything about UserView being undefined.
You won’t get a warning for this. The compiler can’t know at compiletime, if you will have that module available at runtime. Even worse, it can’t even know that you want to try to specify a module there which shall be used to call a function in it later on.
The compiler just sees an alias, which is only syntactic sugar around atoms, and as such UserView (exactly :"Elixir.UserView") does exist from the moment you load the referencing module into memory for the first time until you shut down your BEAM.
Even if we were able to detect, that there is a dynamic function call happening into a module that isn’t available right now during compilation, we can’t know if there might be exactly this module at runtime because its generated somewhere else and simply dropped into the module path.