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 on unrecognized keyword arguments to give suggestions #3750

Closed
oxinabox opened this issue May 20, 2024 · 2 comments · Fixed by #3751
Closed

Fuzzy search on unrecognized keyword arguments to give suggestions #3750

oxinabox opened this issue May 20, 2024 · 2 comments · Fixed by #3751
Labels
Category: Internals Related to JuMP internals Type: Error Messages Can be fixed with better error message

Comments

@oxinabox
Copy link

Welcome. Use this GitHub issue to suggest a new feature for JuMP.

Is your feature request related to a problem? Please describe.

When using JuMP, there are many keyword arguements.
It is sometimes hard to remember exactly how they are spelt.
E.g. casing, pluralization, typos etc.

Describe the solution you'd like
When a keyword argument is not recognized display a list of similar keyword arguments as per fuzzy string distence.

Describe alternatives you've considered
Implement this in Julia itself: JuliaLang/julia#54521
however, JuMP isn't actually hitting the usual path for this, this is a manually thrown error, so implementing it in julia itself would not work.

Additional context
Add any other context or screenshots about the feature request here.

Here is an example:

julia> @variable(model, [1:3], basename=:foo)
ERROR: At REPL[4]:1: `@variable(model, [1:3], basename = :foo)`: Unrecognized keyword argument: basename.

If you're trying to create a JuMP extension, you need to implement `build_variable`. Read the docstring for more details.
Stacktrace:
  [1] error(::String, ::String)
    @ Base ./error.jl:44
  [2] (::JuMP.Containers.var"#error_fn#98"{String})(str::String)
    @ JuMP.Containers ~/.julia/packages/JuMP/Gwn88/src/Containers/macro.jl:325
  [3] build_variable(::JuMP.Containers.var"#error_fn#98"{}, ::VariableInfo{…}; kwargs::@Kwargs{})
    @ JuMP ~/.julia/packages/JuMP/Gwn88/src/macros/@variable.jl:677
  [4] macro expansion ...

I would like the output to include:

 Unrecognized keyword argument: basename.
 Did you mean: base_name ?
@odow
Copy link
Member

odow commented May 20, 2024

This seems pretty reasonable. I've encountered this. The simplest option might just be to enumerate the supported keyword arguments in the error message.

@oxinabox
Copy link
Author

Just enumerating brings it roughly in line with what is used for normal error messages for unmatched keyword arguments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Internals Related to JuMP internals Type: Error Messages Can be fixed with better error message
Development

Successfully merging a pull request may close this issue.

2 participants