From 94af28deb87a603415b2848d377ee5d9ec334ecf Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 16 Jan 2026 10:49:12 +1300 Subject: [PATCH 1/4] Change error msg for GetAttributeNotAllowed when is_set_by_optimize --- src/attributes.jl | 31 ++++++++++++++++++++++++++++ src/error.jl | 47 +++++++++++++++++++++--------------------- test/General/errors.jl | 1 + 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/attributes.jl b/src/attributes.jl index f54123b7e3..3f227d6813 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -129,6 +129,37 @@ operation_name(err::GetAttributeNotAllowed) = "Getting attribute $(err.attr)" message(err::GetAttributeNotAllowed) = err.message +function fix_message(attr::GetAttributeNotAllowed) + if is_set_by_optimize(attr) + return """ + ## Fixing this error + + This error occurs when we cannot query the attribute from the solver. + No other information is available. Check the solver log for details. + """ + end + return """ + ## Fixing this error + + An `MOI.NotAllowedError` error occurs when you have tried to do something that + is not implemented by the solver. + + The most common way to fix this error is to wrap the optimizer in a + `MOI.Utilities.CachingOptimizer`. + + For example, if you are using `JuMP.Model` or `JuMP.set_optimizer`, do: + ```julia + model = JuMP.Model(optimizer; with_cache_type = Float64) + model = JuMP.GenericModel{T}(optimizer; with_cache_type = T) + JuMP.set_optimizer(model, optimizer; with_cache_type = Float64) + ``` + Similarly, if you are using `MOI.instantiate`, do: + ```julia + model = MOI.instantiate(optimizer; with_cache_type = Float64) + ``` + """ +end + """ AbstractSubmittable diff --git a/src/error.jl b/src/error.jl index d8f8876876..05bb0c16e7 100644 --- a/src/error.jl +++ b/src/error.jl @@ -61,32 +61,33 @@ function Base.showerror(io::IO, err::NotAllowedError) println(io, " because:\n\n", m) end println(io) - print( - io, - """ - ## Fixing this error - - An `MOI.NotAllowedError` error occurs when you have tried to do something that - is not implemented by the solver. - - The most common way to fix this error is to wrap the optimizer in a - `MOI.Utilities.CachingOptimizer`. - - For example, if you are using `JuMP.Model` or `JuMP.set_optimizer`, do: - ```julia - model = JuMP.Model(optimizer; with_cache_type = Float64) - model = JuMP.GenericModel{T}(optimizer; with_cache_type = T) - JuMP.set_optimizer(model, optimizer; with_cache_type = Float64) - ``` - Similarly, if you are using `MOI.instantiate`, do: - ```julia - model = MOI.instantiate(optimizer; with_cache_type = Float64) - ``` - """, - ) + print(io, fix_message(err)) return end +function fix_message(::NotAllowedError) + return """ + ## Fixing this error + + An `MOI.NotAllowedError` error occurs when you have tried to do something that + is not implemented by the solver. + + The most common way to fix this error is to wrap the optimizer in a + `MOI.Utilities.CachingOptimizer`. + + For example, if you are using `JuMP.Model` or `JuMP.set_optimizer`, do: + ```julia + model = JuMP.Model(optimizer; with_cache_type = Float64) + model = JuMP.GenericModel{T}(optimizer; with_cache_type = T) + JuMP.set_optimizer(model, optimizer; with_cache_type = Float64) + ``` + Similarly, if you are using `MOI.instantiate`, do: + ```julia + model = MOI.instantiate(optimizer; with_cache_type = Float64) + ``` + """ +end + """ message(err::Union{UnsupportedError, NotAllowedError}) diff --git a/test/General/errors.jl b/test/General/errors.jl index 33eb14d2c4..9c0a47f63b 100644 --- a/test/General/errors.jl +++ b/test/General/errors.jl @@ -361,6 +361,7 @@ function test_get_fallback_error() contents, ) @test occursin("## Fixing this error", contents) + @test occursin("No other information is available", contents) return end From 64e376244e48775cf75b81da3ce9fe7f4f4cb9b6 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 16 Jan 2026 11:12:33 +1300 Subject: [PATCH 2/4] Update --- src/attributes.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/attributes.jl b/src/attributes.jl index 3f227d6813..7ac70c7183 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -129,8 +129,8 @@ operation_name(err::GetAttributeNotAllowed) = "Getting attribute $(err.attr)" message(err::GetAttributeNotAllowed) = err.message -function fix_message(attr::GetAttributeNotAllowed) - if is_set_by_optimize(attr) +function fix_message(err::GetAttributeNotAllowed) + if is_set_by_optimize(err.attr) return """ ## Fixing this error From 34e25b21f0361afd55d95cea38e686b3b724dbc2 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 16 Jan 2026 12:44:11 +1300 Subject: [PATCH 3/4] Update --- test/General/errors.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/General/errors.jl b/test/General/errors.jl index 9c0a47f63b..ae5f471592 100644 --- a/test/General/errors.jl +++ b/test/General/errors.jl @@ -410,6 +410,18 @@ function test_logs_precompile() return end +function test_GetAttributeNotAllowed_showerror() + c_set = sprint(showerror, MOI.GetAttributeNotAllowed(MOI.ConstraintSet())) + @test occursin("## Fixing this error", c_set) + @test occursin("MOI.Utilities.CachingOptimizer", c_set) + @test !occursin("Check the solver log for details.", c_set) + c_dual = sprint(showerror, MOI.GetAttributeNotAllowed(MOI.ConstraintDual())) + @test occursin("## Fixing this error", c_set) + @test !occursin("MOI.Utilities.CachingOptimizer", c_set) + @test occursin("Check the solver log for details.", c_set) + return +end + end # module TestErrors.runtests() From 398fd3394359271e1df2c0ea10d60d166006d15f Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 16 Jan 2026 12:56:10 +1300 Subject: [PATCH 4/4] Update --- test/General/errors.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/General/errors.jl b/test/General/errors.jl index ae5f471592..7dadbba14f 100644 --- a/test/General/errors.jl +++ b/test/General/errors.jl @@ -416,9 +416,9 @@ function test_GetAttributeNotAllowed_showerror() @test occursin("MOI.Utilities.CachingOptimizer", c_set) @test !occursin("Check the solver log for details.", c_set) c_dual = sprint(showerror, MOI.GetAttributeNotAllowed(MOI.ConstraintDual())) - @test occursin("## Fixing this error", c_set) - @test !occursin("MOI.Utilities.CachingOptimizer", c_set) - @test occursin("Check the solver log for details.", c_set) + @test occursin("## Fixing this error", c_dual) + @test !occursin("MOI.Utilities.CachingOptimizer", c_dual) + @test occursin("Check the solver log for details.", c_dual) return end