Skip to content

Commit 45603fe

Browse files
committed
Rethrow for bounds error when modifying constant vector
1 parent def69e1 commit 45603fe

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
@@ -692,8 +692,18 @@ function MOI.modify(
692692
)
693693
try
694694
modify_constants(model.constants, rows(model, ci), change.new_constant)
695-
catch
696-
throw(MOI.ModifyConstraintNotAllowed(ci, change))
695+
catch err
696+
if err isa MethodError
697+
throw(
698+
MOI.ModifyConstraintNotAllowed(
699+
ci,
700+
change,
701+
"`modify_constants` is not implemented for " *
702+
"`$(typeof(model.constants))`",
703+
),
704+
)
705+
end
706+
rethrow(err)
697707
end
698708
return
699709
end

test/Utilities/test_matrix_of_constraints.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,31 @@ function test_modify_vectorsets()
657657
return
658658
end
659659

660+
function test_modify_constants_bounds_error()
661+
model = _new_VectorSets()
662+
src = MOI.Utilities.Model{Int}()
663+
x = MOI.add_variables(src, 2)
664+
c = MOI.add_constraint(
665+
src,
666+
MOI.VectorAffineFunction{Int}(
667+
MOI.VectorAffineTerm.(1, MOI.ScalarAffineTerm.(1, x)),
668+
[1, 3],
669+
),
670+
MOI.SecondOrderCone(2),
671+
)
672+
index_map = MOI.copy_to(model, src)
673+
resize!(model.constraints.constants, 0)
674+
@test_throws(
675+
BoundsError,
676+
MOI.modify(
677+
model.constraints,
678+
index_map[c],
679+
MOI.VectorConstantChange([4, 5]),
680+
),
681+
)
682+
return
683+
end
684+
660685
function test_modify_set_constants()
661686
model = MOI.Utilities.Model{Float64}()
662687
x = MOI.add_variables(model, 3)
@@ -683,8 +708,13 @@ function test_modify_set_constants()
683708
index_map = MOI.copy_to(cache, model)
684709
ci = index_map[p_ref]
685710
change = MOI.VectorConstantChange([4.0, 5.0, 6.0])
711+
constants_type = typeof(cache.constraints.constants)
686712
@test_throws(
687-
MOI.ModifyConstraintNotAllowed(ci, change),
713+
MOI.ModifyConstraintNotAllowed(
714+
ci,
715+
change,
716+
"`modify_constants` is not implemented for `$constants_type`",
717+
),
688718
MOI.modify(cache, ci, change),
689719
)
690720
return

0 commit comments

Comments
 (0)