Skip to content

Commit 052315f

Browse files
authored
show failed Tasks using the same style as TaskFailedException (#35967)
It doesn't really make sense to construct a `CapturedException` just to show a Task.
1 parent d0b2be1 commit 052315f

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

base/show.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function show(io::IO, ::MIME"text/plain", t::Task)
204204
show(io, t)
205205
if t.state === :failed
206206
println(io)
207-
showerror(io, CapturedException(t.result, t.backtrace))
207+
show_task_exception(io, t)
208208
end
209209
end
210210

base/task.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,19 @@ struct TaskFailedException <: Exception
6767
end
6868

6969
function showerror(io::IO, ex::TaskFailedException)
70+
println(io, "TaskFailedException:")
71+
show_task_exception(io, ex.task)
72+
end
73+
74+
function show_task_exception(io::IO, t::Task)
7075
stacks = []
71-
while isa(ex.task.exception, TaskFailedException)
72-
pushfirst!(stacks, ex.task.backtrace)
73-
ex = ex.task.exception
76+
while isa(t.exception, TaskFailedException)
77+
pushfirst!(stacks, t.backtrace)
78+
t = t.exception.task
7479
end
75-
println(io, "TaskFailedException:")
76-
showerror(io, ex.task.exception, ex.task.backtrace)
77-
if !isempty(stacks)
78-
for bt in stacks
79-
show_backtrace(io, bt)
80-
end
80+
showerror(io, t.exception, t.backtrace)
81+
for bt in stacks
82+
show_backtrace(io, bt)
8183
end
8284
end
8385

0 commit comments

Comments
 (0)