Skip to content

Commit

Permalink
Be cautious and print retcode only if available
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Nov 24, 2023
1 parent 45fa653 commit 912f3ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/solutions/nonlinear_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 97 in src/solutions/nonlinear_solutions.jl

View check run for this annotation

Codecov / codecov/patch

src/solutions/nonlinear_solutions.jl#L97

Added line #L97 was not covered by tests

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
4 changes: 3 additions & 1 deletion src/solutions/solution_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Check warning on line 18 in src/solutions/solution_interface.jl

View check run for this annotation

Codecov / codecov/patch

src/solutions/solution_interface.jl#L17-L18

Added lines #L17 - L18 were not covered by tests
end
print(io, "u: ")
show(io, m, A.u)

Check warning on line 21 in src/solutions/solution_interface.jl

View check run for this annotation

Codecov / codecov/patch

src/solutions/solution_interface.jl#L20-L21

Added lines #L20 - L21 were not covered by tests
end
Expand Down

0 comments on commit 912f3ca

Please sign in to comment.