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

Avoid printing values of keyword arguments while displaying a MethodError #45219

Closed
jishnub opened this issue May 7, 2022 · 3 comments · Fixed by #45255
Closed

Avoid printing values of keyword arguments while displaying a MethodError #45219

jishnub opened this issue May 7, 2022 · 3 comments · Fixed by #45255
Labels
error messages Better, more actionable error messages

Comments

@jishnub
Copy link
Contributor

jishnub commented May 7, 2022

Related to this discourse thread

MWE:

julia> f(a::Int; b = nothing) = a
f (generic function with 1 method)

julia> f(2.0, b = zeros(10))
ERROR: MethodError: no method matching f(::Float64; b=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
Closest candidates are:
  f(::Int64; b) at REPL[1]:1
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

The value of the keyword argument has nothing to do with the error, and only adds visual clutter. In some cases, displaying the keyword arguments might take up considerable screen space and be time-consuming.

In case there is a mismatch in the type of the keyword argument, the error thrown is a TypeError, which doesn't show the value of the argument. Arguably, this is the case that might benefit from the values being displayed.

julia> h(a::Int; b::Float64 = 0.0) = a
h (generic function with 1 method)

julia> h(2, b = 4)
ERROR: TypeError: in keyword argument b, expected Float64, got a value of type Int64
Stacktrace:
 [1] top-level scope
   @ REPL[9]:1
@kshyatt kshyatt added the error messages Better, more actionable error messages label May 7, 2022
@JeffBezanson
Copy link
Member

Agree; it doesn't make sense to show the values for keyword arguments and not positional arguments.

@skleinbo
Copy link
Contributor

FWIW, #16669 introduced the behavior.

julia/base/errorshow.jl

Lines 274 to 276 in 59d1d54

for (i, (k, v)) in enumerate(kwargs)
print(io, k, "=")
show(IOContext(io, :limit => true), v)

@KristofferC
Copy link
Member

The behavior is explicitly discussed here #16669 (comment). Possible fix #45255.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Better, more actionable error messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants