Skip to content

Commit 630081f

Browse files
blegatodow
authored andcommitted
Rethrow for bounds error when modifying constant vector
1 parent 0068b8a commit 630081f

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

src/Utilities/matrix_of_constraints.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,18 @@ function MOI.modify(
709709
)
710710
try
711711
modify_constants(model.constants, rows(model, ci), change.new_constant)
712-
catch
713-
throw(MOI.ModifyConstraintNotAllowed(ci, change))
712+
catch err
713+
if err isa MethodError
714+
throw(
715+
MOI.ModifyConstraintNotAllowed(
716+
ci,
717+
change,
718+
"`modify_constants` is not implemented for " *
719+
"`$(typeof(model.constants))`",
720+
),
721+
)
722+
end
723+
rethrow(err)
714724
end
715725
return
716726
end

test/Utilities/test_matrix_of_constraints.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,31 @@ function test_modify_vectorsets()
763763
return
764764
end
765765

766+
function test_modify_constants_bounds_error()
767+
model = _new_VectorSets()
768+
src = MOI.Utilities.Model{Int}()
769+
x = MOI.add_variables(src, 2)
770+
c = MOI.add_constraint(
771+
src,
772+
MOI.VectorAffineFunction{Int}(
773+
MOI.VectorAffineTerm.(1, MOI.ScalarAffineTerm.(1, x)),
774+
[1, 3],
775+
),
776+
MOI.SecondOrderCone(2),
777+
)
778+
index_map = MOI.copy_to(model, src)
779+
resize!(model.constraints.constants, 0)
780+
@test_throws(
781+
BoundsError,
782+
MOI.modify(
783+
model.constraints,
784+
index_map[c],
785+
MOI.VectorConstantChange([4, 5]),
786+
),
787+
)
788+
return
789+
end
790+
766791
function test_modify_set_constants()
767792
model = MOI.Utilities.Model{Float64}()
768793
x = MOI.add_variables(model, 3)
@@ -789,8 +814,13 @@ function test_modify_set_constants()
789814
index_map = MOI.copy_to(cache, model)
790815
ci = index_map[p_ref]
791816
change = MOI.VectorConstantChange([4.0, 5.0, 6.0])
817+
constants_type = typeof(cache.constraints.constants)
792818
@test_throws(
793-
MOI.ModifyConstraintNotAllowed(ci, change),
819+
MOI.ModifyConstraintNotAllowed(
820+
ci,
821+
change,
822+
"`modify_constants` is not implemented for `$constants_type`",
823+
),
794824
MOI.modify(cache, ci, change),
795825
)
796826
return

0 commit comments

Comments
 (0)