From 912f3ca143e4fadc6a92b39a30d37e8195a8420e Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Fri, 24 Nov 2023 13:27:59 -0500 Subject: [PATCH] Be cautious and print retcode only if available --- src/solutions/nonlinear_solutions.jl | 7 +++++-- src/solutions/solution_interface.jl | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/solutions/nonlinear_solutions.jl b/src/solutions/nonlinear_solutions.jl index 31e319105..041f88302 100644 --- a/src/solutions/nonlinear_solutions.jl +++ b/src/solutions/nonlinear_solutions.jl @@ -93,8 +93,11 @@ function sensitivity_solution(sol::AbstractNonlinearSolution, u) T = eltype(eltype(u)) N = ndims(u) + # Some of the subtypes might not have a trace field + trace = hasfield(typeof(sol), :trace) ? sol.trace : nothing + NonlinearSolution{T, N, typeof(u), typeof(sol.resid), typeof(sol.prob), typeof(sol.alg), typeof(sol.original), typeof(sol.left), - typeof(sol.stats), trace(sol.trace)}(u, sol.resid, sol.prob, sol.alg, sol.retcode, - sol.original, sol.left, sol.right, sol.stats, sol.trace) + typeof(sol.stats), trace(trace)}(u, sol.resid, sol.prob, sol.alg, sol.retcode, + sol.original, sol.left, sol.right, sol.stats, trace) end diff --git a/src/solutions/solution_interface.jl b/src/solutions/solution_interface.jl index 640ab06d6..04dc0e152 100644 --- a/src/solutions/solution_interface.jl +++ b/src/solutions/solution_interface.jl @@ -14,7 +14,9 @@ Base.setindex!(A::AbstractNoTimeSolution, v, I::Vararg{Int, N}) where {N} = (A.u Base.size(A::AbstractNoTimeSolution) = size(A.u) function Base.show(io::IO, m::MIME"text/plain", A::AbstractNoTimeSolution) - println(io, string("retcode: ", A.retcode)) + if hasfield(typeof(A), :retcode) + println(io, string("retcode: ", A.retcode)) + end print(io, "u: ") show(io, m, A.u) end