Skip to content

Commit

Permalink
show failed Tasks using the same style as TaskFailedException (#35967)
Browse files Browse the repository at this point in the history
It doesn't really make sense to construct a `CapturedException`
just to show a Task.
  • Loading branch information
JeffBezanson authored May 27, 2020
1 parent d0b2be1 commit 052315f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function show(io::IO, ::MIME"text/plain", t::Task)
show(io, t)
if t.state === :failed
println(io)
showerror(io, CapturedException(t.result, t.backtrace))
show_task_exception(io, t)
end
end

Expand Down
20 changes: 11 additions & 9 deletions base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,19 @@ struct TaskFailedException <: Exception
end

function showerror(io::IO, ex::TaskFailedException)
println(io, "TaskFailedException:")
show_task_exception(io, ex.task)
end

function show_task_exception(io::IO, t::Task)
stacks = []
while isa(ex.task.exception, TaskFailedException)
pushfirst!(stacks, ex.task.backtrace)
ex = ex.task.exception
while isa(t.exception, TaskFailedException)
pushfirst!(stacks, t.backtrace)
t = t.exception.task
end
println(io, "TaskFailedException:")
showerror(io, ex.task.exception, ex.task.backtrace)
if !isempty(stacks)
for bt in stacks
show_backtrace(io, bt)
end
showerror(io, t.exception, t.backtrace)
for bt in stacks
show_backtrace(io, bt)
end
end

Expand Down

0 comments on commit 052315f

Please sign in to comment.