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

[Error printing] Distinguish having no applicable function and manually thrown MethodErrors #36182

Closed
rapus95 opened this issue Jun 7, 2020 · 1 comment · Fixed by #53164
Closed
Labels
error handling Handling of exceptions by Julia or the user

Comments

@rapus95
Copy link
Contributor

rapus95 commented Jun 7, 2020

In order to progress on the long way to perfect, beautiful and userfriendly error messages and to reduce irritations like those:

julia> div(5,2,RoundFromZero)
ERROR: MethodError: no method matching div(::Int64, ::Int64, ::RoundingMode{:FromZero})
Closest candidates are:
  div(::Real, ::Real, ::RoundingMode) at div.jl:247
  div(::Missing, ::Number, ::RoundingMode) at missing.jl:121
  div(::T, ::T) where T<:Union{Int16, Int32, Int64, Int8} at int.jl:230
  ...
Stacktrace:
 [1] div(::Int64, ::Int64, ::RoundingMode{:FromZero}) at .\div.jl:247
 [2] top-level scope at REPL[51]:1

julia> @which div(5,2,RoundFromZero)
div(x::Real, y::Real, r::RoundingMode) in Base at div.jl:247

(This particular error has already a bug report there #34519)
where it clearly looks like there are applicable methods and in fact are, I'd suggest to somehow leverage that information for the user that there indeed are functions which have compatible signature but can't handle that actual signature.

Every time I stumble over such a case I first check it like 3 times whether I overlooked something in the signature but come to the conclusion that it should find its applicable function. Once I dive into the function via @edit I see that a MethodError was thrown manually.

At the very least it looks somewhat inconsistent to me. An idea to tackle that problem would be to introduce a manual flag (naming of that flag is open to discussion) which can be passed to the MethodError constructor and is true by default. Only in the places where the MethodError is thrown because there are no applicable methods at all, that flag should hold the value false. Then, on printing the error, we could easily distinguish those cases.

Even though the steps to solve that error are the same in both cases, namingly, defining the missing function, it helps reducing confusion and increases consistency IMO.

@rapus95 rapus95 changed the title Distinguish having no applicable function and manually thrown MethodErrors [Error printing] Distinguish having no applicable function and manually thrown MethodErrors Jun 7, 2020
@JeffBezanson
Copy link
Member

The manual flag should not be necessary, since as you say we can look at the method table to see that there is a non-ambiguous matching method.

@JeffBezanson JeffBezanson added the error handling Handling of exceptions by Julia or the user label Jun 8, 2020
vtjnash added a commit that referenced this issue Feb 1, 2024
Distinguish some of the cases of manually thrown MethodError by looking
for a method in the specified world. Also refactor some of the kwcall
handling to be closer to supporting `invoke`d calls (although it does
not guaranteed to have a value for `f`, which is often required later).

Fixes #36182
vtjnash added a commit that referenced this issue Feb 1, 2024
Distinguish some of the cases of manually thrown MethodError by looking
for a method in the specified world. Also refactor some of the kwcall
handling to be closer to supporting `invoke`d calls (although it does
not guaranteed to have a value for `f`, which is often required later).

Fixes #36182
vtjnash added a commit that referenced this issue Feb 1, 2024
Distinguish some of the cases of manually thrown MethodError by looking
for a method in the specified world. Also refactor some of the kwcall
handling to be closer to supporting `invoke`d calls (although it does
not guaranteed to have a value for `f`, which is often required later).

Fixes #36182
vtjnash added a commit that referenced this issue Feb 1, 2024
Distinguish some of the cases of manually thrown MethodError by looking
for a method in the specified world. Also refactor some of the kwcall
handling to be closer to supporting `invoke`d calls (although it does
not guaranteed to have a value for `f`, which is often required later).

Fixes #36182
vtjnash added a commit that referenced this issue Feb 3, 2024
Distinguish some of the cases of manually thrown MethodError by looking
for a method in the specified world. Also refactor some of the kwcall
handling to be closer to supporting `invoke`d calls (although it does
not guaranteed to have a value for `f`, which is often required later).

Fixes #36182
vtjnash added a commit that referenced this issue Feb 5, 2024
Distinguish some of the cases of manually thrown MethodError by looking
for a method in the specified world. Also refactor some of the kwcall
handling to be closer to supporting `invoke`d calls (although it does
not guaranteed to have a value for `f`, which is often required later).

Fixes #36182
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants