Skip to content

Commit

Permalink
Improve error message for unsupported kwargs in variable macro (#3751)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored May 21, 2024
1 parent a62eae7 commit ba2ded5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
22 changes: 19 additions & 3 deletions src/macros/@variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,25 @@ function build_variable(
)
end
error_fn(
"Unrecognized keyword argument: $key.\n\nIf you're trying " *
"to create a JuMP extension, you need to implement " *
"`build_variable`. Read the docstring for more details.",
"""
Unrecognized keyword argument: $key.
The supported keyword arguments are:
* `base_name`
* `binary`
* `container`
* `integer`
* `lower_bound`
* `set`
* `set_string_name`
* `start`
* `upper_bound`
* `variable_type`
If you're trying to create a JuMP extension, you need to implement `JuMP.build_variable`.
See the docstring for more details.
""",
)
end
if info.lower_bound isa AbstractArray
Expand Down
23 changes: 19 additions & 4 deletions test/test_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -914,10 +914,25 @@ end
function test_unrecognized_kwarg()
model = Model()
err = ErrorException(
"In `@variable(model, x, foo = 1)`: " *
"Unrecognized keyword argument: foo.\n\nIf you're trying to " *
"create a JuMP extension, you need to implement " *
"`build_variable`. Read the docstring for more details.",
"""
In `@variable(model, x, foo = 1)`: Unrecognized keyword argument: foo.
The supported keyword arguments are:
* `base_name`
* `binary`
* `container`
* `integer`
* `lower_bound`
* `set`
* `set_string_name`
* `start`
* `upper_bound`
* `variable_type`
If you're trying to create a JuMP extension, you need to implement `JuMP.build_variable`.
See the docstring for more details.
""",
)
@test_throws_runtime err @variable(model, x, foo = 1)
return
Expand Down

0 comments on commit ba2ded5

Please sign in to comment.