Skip to content

Commit 912f3ca

Browse files
committed
Be cautious and print retcode only if available
1 parent 45fa653 commit 912f3ca

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/solutions/nonlinear_solutions.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ function sensitivity_solution(sol::AbstractNonlinearSolution, u)
9393
T = eltype(eltype(u))
9494
N = ndims(u)
9595

96+
# Some of the subtypes might not have a trace field
97+
trace = hasfield(typeof(sol), :trace) ? sol.trace : nothing
98+
9699
NonlinearSolution{T, N, typeof(u), typeof(sol.resid), typeof(sol.prob),
97100
typeof(sol.alg), typeof(sol.original), typeof(sol.left),
98-
typeof(sol.stats), trace(sol.trace)}(u, sol.resid, sol.prob, sol.alg, sol.retcode,
99-
sol.original, sol.left, sol.right, sol.stats, sol.trace)
101+
typeof(sol.stats), trace(trace)}(u, sol.resid, sol.prob, sol.alg, sol.retcode,
102+
sol.original, sol.left, sol.right, sol.stats, trace)
100103
end

src/solutions/solution_interface.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ Base.setindex!(A::AbstractNoTimeSolution, v, I::Vararg{Int, N}) where {N} = (A.u
1414
Base.size(A::AbstractNoTimeSolution) = size(A.u)
1515

1616
function Base.show(io::IO, m::MIME"text/plain", A::AbstractNoTimeSolution)
17-
println(io, string("retcode: ", A.retcode))
17+
if hasfield(typeof(A), :retcode)
18+
println(io, string("retcode: ", A.retcode))
19+
end
1820
print(io, "u: ")
1921
show(io, m, A.u)
2022
end

0 commit comments

Comments
 (0)