Skip to content

Commit

Permalink
Improve stacktrace of errors thrown from within a callback
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed May 15, 2024
1 parent 596b3a8 commit 23299f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function _internal_callback(tree::Ptr{Cvoid}, info::Ptr{Cvoid})
cb_data.callback_function(cb_data)
catch ex
glp_ios_terminate(tree)
cb_data.exception = ex
cb_data.exception = CapturedException(ex, catch_backtrace())
end
return Cint(0)
end
Expand Down
19 changes: 19 additions & 0 deletions test/MOI_callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,25 @@ function test_no_cache_InterruptException()
return
end

function test_issue_232()
model = GLPK.Optimizer()
x = MOI.add_variable(model)
MOI.add_constraint(model, x, MOI.ZeroOne())
my_callback(args...) = error("FooBar")
MOI.set(model, GLPK.CallbackFunction(), my_callback)
try
MOI.optimize!(model)
# To ensure that if an error is not thrown from the callback we still
# hit the catch block
@assert false
catch ex
@test ex isa CapturedException
@test occursin("my_callback", "$ex")
@test occursin("FooBar", "$ex")
end
return
end

end

TestCallbacks.runtests()

0 comments on commit 23299f1

Please sign in to comment.