From 652326df7e7b3c65a0e1a49bedf63682b852c0a9 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 1 May 2026 15:54:33 +1200 Subject: [PATCH 1/2] Remove callback_exception --- src/MOI/MOI_callbacks.jl | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/MOI/MOI_callbacks.jl b/src/MOI/MOI_callbacks.jl index bdaa4974..5781d714 100644 --- a/src/MOI/MOI_callbacks.jl +++ b/src/MOI/MOI_callbacks.jl @@ -45,7 +45,8 @@ function MOI.set(model::Optimizer, ::CallbackFunction, f::Function) if ex isa InterruptException _ = XPRSinterrupt(model, XPRS_STOP_CTRLC) else - callback_exception(model, cb_data, ex) + model.cb_exception = ex + _ = XPRSinterrupt(cb_data.model, XPRS_STOP_USER) end end model.callback_state = CB_NONE @@ -166,12 +167,6 @@ function MOI.get( return model.callback_cached_solution.variable_primal[column] end -function callback_exception(model::Optimizer, cb, err::Exception) - model.cb_exception = err - _ = XPRSinterrupt(cb.callback_data.model, XPRS_STOP_USER) - return -end - function _throw_if_invalid_state(model, cb, calling_state) if model.callback_state in (calling_state, CB_NONE, CB_GENERIC) return @@ -184,7 +179,9 @@ function _throw_if_invalid_state(model, cb, calling_state) @assert model.callback_state == CB_USER_CUT MOI.UserCutCallback() end - return callback_exception(model, cb, MOI.InvalidCallbackUsage(attr, cb)) + model.cb_exception = MOI.InvalidCallbackUsage(attr, cb) + _ = XPRSinterrupt(cb.callback_data.model, XPRS_STOP_USER) + return end # ============================================================================== From ea6622cbd497f3d59b265d4ba96764f93f2be6fa Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 1 May 2026 17:41:26 +1200 Subject: [PATCH 2/2] Add test --- test/test_MOI_wrapper.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test_MOI_wrapper.jl b/test/test_MOI_wrapper.jl index 78a12f28..9db375b5 100644 --- a/test/test_MOI_wrapper.jl +++ b/test/test_MOI_wrapper.jl @@ -2332,6 +2332,13 @@ function test_InterruptException() return end +function test_error_in_callback() + model, _, _ = callback_knapsack_model() + MOI.set(model, Xpress.CallbackFunction(), cb -> error("Error in callback")) + @test_throws ErrorException("Error in callback") MOI.optimize!(model) + return +end + end # TestMOIWrapper TestMOIWrapper.runtests()