Skip to content
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
7 changes: 7 additions & 0 deletions docs/src/apireference.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,13 @@ inside a callback may throw:
OptimizeInProgress
```

Trying to submit the wrong type of [`AbstractSubmittable`](@ref) inside an
[`AbstractCallback`](@ref) (e.g., a [`UserCut`](@ref) inside a
[`LazyConstraintCallback`](@ref)) will throw:
```@docs
InvalidCallbackUsage
```

The rest of the errors defined in MOI fall in two categories represented by the
following two abstract types:
```@docs
Expand Down
21 changes: 21 additions & 0 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,27 @@ struct UserCut{CallbackDataType} <: AbstractSubmittable
callback_data::CallbackDataType
end

"""
struct InvalidCallbackUsage{C, S} <: Exception
callback::C
submittable::S
end

An error indicating that `submittable` cannot be submitted inside `callback`.

For example, [`UserCut`](@ref) cannot be submitted inside
[`LazyConstraintCallback`](@ref).
"""
struct InvalidCallbackUsage{C, S} <: Exception
callback::C
submittable::S
end

function Base.showerror(io::IO, err::InvalidCallbackUsage)
print(io, "InvalidCallbackUsage: Cannot submit $(err.submittable) inside a $(err.callback).")
end


## Optimizer attributes

"""
Expand Down
5 changes: 5 additions & 0 deletions test/errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,9 @@ end
MOI.ResultIndexBoundsError(MOI.VariablePrimal(1), 0)
) == "Result index of attribute MathOptInterface.VariablePrimal(1) out of" *
" bounds. There are currently 0 solution(s) in the model."

@test sprint(
showerror,
MOI.InvalidCallbackUsage(MOI.LazyConstraintCallback(), MOI.UserCut(1))
) == "InvalidCallbackUsage: Cannot submit $(MOI.UserCut(1)) inside a MathOptInterface.LazyConstraintCallback()."
end