Skip to content

Extract stacktrace from the failed task #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/taskcopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ proper way is refreshing the `current_task` (the variable `t`) in
function task_wrapper(func)
() ->
try
res = func()
ct = current_task()
res = func()
ct.result = res
isa(ct.storage, Nothing) && (ct.storage = IdDict())
ct.storage[:_libtask_state] = :done
Expand Down Expand Up @@ -83,6 +83,20 @@ function Base.copy(t::Task)
newt
end

struct CTaskException
etype
msg::String
backtrace::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}
end

function Base.show(io::IO, exc::CTaskException)
println(io, "Stacktrace in the failed task:\n")
println(io, exc.msg * "\n")
for line in stacktrace(exc.backtrace)
println(io, string(line))
end
end

produce(v) = begin
ct = current_task()

Expand Down Expand Up @@ -178,7 +192,12 @@ consume(p::Task, values...) = begin
return p.result
end
if p.exception != nothing
throw(p.exception)
msg = if :msg in fieldnames(typeof(p.exception))
p.exception.msg
else
string(typeof(p.exception))
end
throw(CTaskException(typeof(p.exception), msg, p.backtrace))
end
end
wait()
Expand Down
8 changes: 4 additions & 4 deletions test/brokentask.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ r = @testset "Broken Functions Tests" begin
try
consume(t)
catch ex
@test isa(ex, ErrorException)
@test ex.etype == ErrorException
end
@test isa(t.exception, ErrorException)
end
Expand All @@ -37,7 +37,7 @@ r = @testset "Broken Functions Tests" begin
try
consume(t)
catch ex
@test isa(ex, BoundsError)
@test ex.etype == BoundsError
end
@test isa(t.exception, BoundsError)
end
Expand All @@ -58,7 +58,7 @@ r = @testset "Broken Functions Tests" begin
try
consume(t)
catch ex
@test isa(ex, BoundsError)
@test ex.etype == BoundsError
end
@test isa(t.exception, BoundsError)
end
Expand All @@ -80,7 +80,7 @@ r = @testset "Broken Functions Tests" begin
try
consume(t_copy)
catch ex
@test isa(ex, BoundsError)
@test ex.etype == BoundsError
end
@test isa(t_copy.exception, BoundsError)
end
Expand Down
2 changes: 1 addition & 1 deletion test/clonetask.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ function g_break()
end

t = CTask(g_break)
@test_throws MethodError consume(t)
@test_throws Libtask.CTaskException consume(t)