Skip to content
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

More user-friendly methods not found error messages #10620

Closed
ViralBShah opened this issue Mar 24, 2015 · 6 comments
Closed

More user-friendly methods not found error messages #10620

ViralBShah opened this issue Mar 24, 2015 · 6 comments
Labels
domain:error handling Handling of exceptions by Julia or the user status:help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@ViralBShah
Copy link
Member

I am helping someone port their code to julia and found myself wanting better error messages for methods not found. The codebase I am working on is not long, but it is a bit involved, with lots of functions that take 10-20 arguments. It is easy to pass a wrong type for one or more arguments or pass a different number of arguments. It would be nice if the method not found error message could be improved further.

Currently, we already do this. For example:

julia> sin(5,5)
ERROR: MethodError: `sin` has no method matching sin(::Int64, ::Int64)
Closest candidates are:
  sin(::Real)

What would be nice is to also print the number of arguments in the error message and the closest candidate, if the number of arguments is greater than 5 or something.

@mbauman mbauman added the domain:error handling Handling of exceptions by Julia or the user label Mar 24, 2015
@tkelman
Copy link
Contributor

tkelman commented Mar 25, 2015

lots of functions that take 10-20 arguments

Code smell much? In Matlab I would refactor that into taking one or a handful of structs pronto, in Julia would either a Dict or a composite type make sense for that interface?

Not to say the error couldn't be made fancier and count commas for you, but if you're having to count commas that's not a good sign...

@StefanKarpinski
Copy link
Sponsor Member

I'm not entirely sure how much clearer we could make such error messages, but @ViralBShah, if you've got ideas on how to display the more clearly, why not make it easier?

@ivarne
Copy link
Sponsor Member

ivarne commented Mar 25, 2015

An example suggestion of the output you want to get would be great! It's easier to discuss the details when we have something to look at.

@ViralBShah
Copy link
Member Author

Of course, such code needs refactoring. Even during such refactoring, it would be useful to have better messages. We already took a step towards this in 0.4 with the "closest candidates", which is not present in 0.3. I can think of two things that could be useful:

  1. If the number of arguments are not matching, print the number of arguments.
  2. Point out which argument is mismatched, if many arguments are of the right type. It turns out we already do this by printing the mismatched arguments in red. For anything more than a handful of arguments, it would be great to have numbers on each of the arguments

For example:

julia> foo(a::Int,b::Int,c::Int,d::Int,e::Int) = 1
julia> foo(1,2,3,"hello",5,6)
ERROR: MethodError: `foo` has no method matching 
foo(::Int64, ::Int64, ::Int64, ::ASCIIString, ::Int64, ::Int64) with 6 arguments
Closest candidates are:
  foo(::Int64 [1], ::Int64 [2], ::Int64 [3], <red>::Int64</red> [4], ::Int64 [5]) 
with 5 arguments

The coloring is already implemented.

@ivarne
Copy link
Sponsor Member

ivarne commented Mar 25, 2015

I think that is a good starting point for a up for grabs issue

The relevant code is in base/replutil.jl

@ivarne ivarne added the status:help wanted Indicates that a maintainer wants help on an issue or pull request label Mar 25, 2015
@jakebolewski
Copy link
Member

I don't see how you can do this generally. How do you distinguish arguments with default parameters / keyword arguments? The no method error messages would become very verbose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:error handling Handling of exceptions by Julia or the user status:help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

6 participants