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

Improve error message for unsupported kwargs in variable macro #3751

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading