-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Improve error on module case mismatch #5665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hmm, tests succeed on my Mac. I'm guessing Travis runs on a case-sensitive filesystem, so this is treated as a simple missing module error. The problem with a more generic solution is that it would require traversing the code path to find potential alternatives... |
@fishcakez do you think |
@@ -640,8 +640,26 @@ defmodule UndefinedFunctionError do | |||
end | |||
|
|||
def message(%{reason: :"module could not be loaded", module: module, function: function, arity: arity}) do | |||
suffix = | |||
case :code.get_object_code(module) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will probably be cleaner if you use the with
construct. Also keep in mind we can pass the second argument from :code.get_object_code
to :beam_lib
. Here is one suggestion:
suffix =
with {_, binary, _} <- :code.get_object_code(module),
{:ok, {alt_module, _}} <- :beam_lib.chunks(binary, []) do
exports = exports_for(alt_module)
if ... do ... else ... end
else
_ -> ""
end
I am keen on this change because |
Yeah, I wanted to avoid traversing the code path to look for the module that Would there be any way to determine the name of the BEAM file |
I am not sure what we can do :(. If |
OK, so I'll look at a possible log translator. If the concern is the runtime impact, perhaps I can move the code out of the exception and into the |
Being able to detect module typos with |
Regarding log translation, I can translate this:
...into this:
It requires a call to |
@voltone I like that! I would just say:
@fishcakez, what do you think? |
@josevalim The reason I dropped the path is because it includes the 'mutilated' filename, and besides, it's noise that detracts from the root cause the message tries to highlight. No? |
@voltone it is mostly noise but it may be useful in some situations. For example, imagine someone accidentally have a .beam file in the root of the current project named Foobar while in the project they use FooBar. Then Foobar would be picked up, they would see the warning, but never realized it is because of a beam file at root. If you want to put less attention to it, you can put the "in path/to/beam" in parentheses. |
It should be |
On a case-insensitive filesystem, a module case mismatch typo results in error messages that can be confusing:
The
:code_server
log messages do show the root cause, but it's easy to miss, and in a way they obscure the problem by suggesting the problem is in the .beam file.This PR provides a more helpful message (the
:code_server
log messages still appear):Question: would it be possible/desirable to suppress the
:code_server
log messages?The
xref
Mix task has been updated to provide the same message as well./cc @benwilson512