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

Fuzzy search in MethodError for incorrect keyword arguments #54521

Open
oxinabox opened this issue May 20, 2024 · 0 comments
Open

Fuzzy search in MethodError for incorrect keyword arguments #54521

oxinabox opened this issue May 20, 2024 · 0 comments

Comments

@oxinabox
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant