julia icon indicating copy to clipboard operation
julia copied to clipboard

Fuzzy search in MethodError for incorrect keyword arguments

Open oxinabox opened this issue 1 year ago • 0 comments

Consider when you get a keyword argument wrong you currently get a plain MethodError. This does highlight that the keyword argument was wrong, but it could be made better.

In particular, we could use our fuzzy search to find similar names. e.g. right now we get

julia> foo(; bar=1) = 1
foo (generic function with 1 method)

julia> foo(; bars=2)
ERROR: MethodError: no method matching foo(; bars::Int64)

Closest candidates are:
  foo(; bar) got unsupported keyword argument "bars"
   @ Main REPL[6]:1

Stacktrace:
 [1] kwerr(kw::@NamedTuple{bars::Int64}, args::Function)
   @ Base ./error.jl:165
 [2] top-level scope
   @ REPL[7]:1

We could be saying did you mean "bar"?

This is more helpful when there is a lot of keyword arguments. And we could probably just list the top 3 by fuzzy distance.

Though this will not work for any function that takes varadic keyword arguments, which I suspect is most common for things with many many keyword arguments.

oxinabox avatar May 20 '24 06:05 oxinabox