Skip to content

Conversation

@tonini
Copy link
Contributor

@tonini tonini commented Oct 31, 2013

The expected behavior for nil.func() should be:

iex(1)> nil.test()
** (UndefinedFunctionError) undefined function: nil.test/0
   nil.test()

Also via cli elixir -e:

$ elixir -e 'nil.test()'
** (UndefinedFunctionError) undefined function: nil.test/0
   nil.test()
   ....

@josevalim as you can see I explicit give an :no_module symbol as argument for the module inside of normalize_exception/2 function to get around the problem that nil get in front of every function name inside of the UndefinedFunctionError exception.

Maybe it's not the nicest solution, I'm open for feedback and ideas. :)

reference: #1823

@ericmj
Copy link
Member

ericmj commented Oct 31, 2013

Note about no addition tests, there was no need to add more test to handle the case between nil.test() and foo.test() because there already tests which handle this case: https://github.com/elixir-lang/elixir/blob/master/lib/iex/test/iex/interaction_test.exs?source=cc

I find no tests for this in that file. https://github.com/elixir-lang/elixir/blob/master/lib/elixir/test/elixir/exception_test.exs would be a good place to add tests.

@josevalim as you can see I explicit give an empty string as argument for the module inside of normalize_exception/2 function to get around the problem that nil get in front of every function name inside of the UndefinedFunctionError exception.

I would go with something as :no_module instead of empty string. Maybe there is a nicer solution...

@tonini
Copy link
Contributor Author

tonini commented Oct 31, 2013

@ericmj Good point.

I would go with something as :no_module instead of empty string. Maybe there is a nicer solution...

I will add tests and also use the :no_moduleinstead of an empty string.

@tonini
Copy link
Contributor Author

tonini commented Oct 31, 2013

@ericmj @josevalim I made the changes

  • :no_module instead of an non-informativ empty string (thx @ericmj :)
  • add explicit tests for it.

@josevalim what's about this raise_preserves_the_stacktrace test inside of exception_tests.exs could't the explicit line number be replaced with an _?. Is the explicit line number needed to be a proper test in this case?

good night. 🌔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ericmj and @tonini! I don't think the :no_module is a good approach though because :no_module is still a valid atom name. I think the best to do here is to stop using UndefinedFunctionError and simply return RuntimeError[message: "undefined function #{function}/#{arity}"] (note arity can be a list, so we need to convert it to an integer if so).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:no_module is still a valid atom name

Ok I see what you mean.

I will update the source with using a RuntimeError instead for a review.

@josevalim
Copy link
Member

@josevalim what's about this raise_preserves_the_stacktrace test inside of exception_tests.exs could't the explicit line number be replaced with an _?. Is the explicit line number needed to be a proper test in this case?

Yeah, we are testing exactly the number doesn't change. We have a couple tests like that in the suite. :)

@josevalim
Copy link
Member

We could probably fix those tests to use some combination of __ENV__.line though.

@tonini
Copy link
Contributor Author

tonini commented Nov 1, 2013

@josevalim You showed the error message above like : "undefined function #{function}/#{arity}"] but at the moment it's not showing the amount of the arity, instead the list of arguments itself like: undefined function: foo(123, "bar", [123, 4])

Would you like to change the current message style or leave it as it is?

@josevalim
Copy link
Member

Let's just show the arity. This error can only happen when the user types no_helper(1, 2, 3) so the actual arguments are just one line above, there is no need to repeat them. :)

@tonini
Copy link
Contributor Author

tonini commented Nov 1, 2013

ok. :)


Sent from Mailbox for iPhone

On Fri, Nov 1, 2013 at 11:38 AM, José Valim notifications@github.com
wrote:

Let's just show the arity. This error can only happen when the user types no_helper(1, 2, 3) so the actual arguments are just one line above, there is no need to repeat them. :)

Reply to this email directly or view it on GitHub:
#1834 (comment)

@tonini
Copy link
Contributor Author

tonini commented Nov 1, 2013

@josevalim @ericmj Ok I'm done with a first realization, please review and give feedback if needed. ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it can ever not be one of those, so I would get rid of this clause. Everything else is perfect. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you talk about the true -> clause` ?

The expected behavior for `nil.func()` should be:

    iex(1)> nil.test()
    ** (UndefinedFunctionError) undefined function: nil.test/0
       nil.test()

Also via cli `elixir -e`:

     $ elixir -e 'nil.test()'
     ** (UndefinedFunctionError) undefined function: nil.test/0
     nil.test()
     ....

Undefined function calls behave like:

    iex(1)> hello()
    ** (RuntimeError) undefined function: hello/0
@tonini
Copy link
Contributor Author

tonini commented Nov 1, 2013

@josevalim The clause is updated. :)

josevalim pushed a commit that referenced this pull request Nov 1, 2013
fix wrong error message for `nil.func()` call
@josevalim josevalim merged commit d92175a into elixir-lang:master Nov 1, 2013
@josevalim
Copy link
Member

❤️ 💚 💙 💛 💜

@ericmj
Copy link
Member

ericmj commented Nov 1, 2013

Awesome @tonini!

@tonini
Copy link
Contributor Author

tonini commented Nov 1, 2013

My pleasure!

@tonini tonini deleted the fix-wrong-error-message branch November 1, 2013 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants