Skip to content

Commit 6963197

Browse files
author
KDr2
committed
Extract stacktrace from the failed task
1 parent f59baf5 commit 6963197

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/taskcopy.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ proper way is refreshing the `current_task` (the variable `t`) in
4040
function task_wrapper(func)
4141
() ->
4242
try
43-
res = func()
4443
ct = current_task()
44+
res = func()
4545
ct.result = res
4646
isa(ct.storage, Nothing) && (ct.storage = IdDict())
4747
ct.storage[:_libtask_state] = :done
@@ -83,6 +83,19 @@ function Base.copy(t::Task)
8383
newt
8484
end
8585

86+
struct CTaskException
87+
msg::String
88+
backtrace::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}
89+
end
90+
91+
function Base.show(io::IO, exc::CTaskException)
92+
println(io, "Stacktrace in the failed task:\n")
93+
println(io, exc.msg * "\n")
94+
for line in stacktrace(exc.backtrace)
95+
println(io, string(line))
96+
end
97+
end
98+
8699
produce(v) = begin
87100
ct = current_task()
88101

@@ -178,7 +191,7 @@ consume(p::Task, values...) = begin
178191
return p.result
179192
end
180193
if p.exception != nothing
181-
throw(p.exception)
194+
throw(CTaskException(p.exception.msg, p.backtrace))
182195
end
183196
end
184197
wait()

0 commit comments

Comments
 (0)