jump-dev / JuMP.jl

Modeling language for Mathematical Optimization (linear, mixed-integer, conic, semidefinite, nonlinear)
http://jump.dev/JuMP.jl/
Other
2.17k stars 390 forks source link

Fuzzy search on unrecognized keyword arguments to give suggestions #3750

Closed oxinabox closed 1 month ago

oxinabox commented 1 month ago

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: https://github.com/JuliaLang/julia/issues/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 commented 1 month ago

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 commented 1 month ago

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