File tree Expand file tree Collapse file tree 3 files changed +26
-7
lines changed Expand file tree Collapse file tree 3 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -40,8 +40,8 @@ proper way is refreshing the `current_task` (the variable `t`) in
4040function 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,20 @@ function Base.copy(t::Task)
8383 newt
8484end
8585
86+ struct CTaskException
87+ etype
88+ msg:: String
89+ backtrace:: Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}
90+ end
91+
92+ function Base. show (io:: IO , exc:: CTaskException )
93+ println (io, " Stacktrace in the failed task:\n " )
94+ println (io, exc. msg * " \n " )
95+ for line in stacktrace (exc. backtrace)
96+ println (io, string (line))
97+ end
98+ end
99+
86100produce (v) = begin
87101 ct = current_task ()
88102
@@ -178,7 +192,12 @@ consume(p::Task, values...) = begin
178192 return p. result
179193 end
180194 if p. exception != nothing
181- throw (p. exception)
195+ msg = if :msg in fieldnames (typeof (p. exception))
196+ p. exception. msg
197+ else
198+ string (typeof (p. exception))
199+ end
200+ throw (CTaskException (typeof (p. exception), msg, p. backtrace))
182201 end
183202 end
184203 wait ()
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ r = @testset "Broken Functions Tests" begin
1717 try
1818 consume (t)
1919 catch ex
20- @test isa (ex, ErrorException)
20+ @test ex . etype == ErrorException
2121 end
2222 @test isa (t. exception, ErrorException)
2323 end
@@ -37,7 +37,7 @@ r = @testset "Broken Functions Tests" begin
3737 try
3838 consume (t)
3939 catch ex
40- @test isa (ex, BoundsError)
40+ @test ex . etype == BoundsError
4141 end
4242 @test isa (t. exception, BoundsError)
4343 end
@@ -58,7 +58,7 @@ r = @testset "Broken Functions Tests" begin
5858 try
5959 consume (t)
6060 catch ex
61- @test isa (ex, BoundsError)
61+ @test ex . etype == BoundsError
6262 end
6363 @test isa (t. exception, BoundsError)
6464 end
@@ -80,7 +80,7 @@ r = @testset "Broken Functions Tests" begin
8080 try
8181 consume (t_copy)
8282 catch ex
83- @test isa (ex, BoundsError)
83+ @test ex . etype == BoundsError
8484 end
8585 @test isa (t_copy. exception, BoundsError)
8686 end
Original file line number Diff line number Diff line change @@ -56,4 +56,4 @@ function g_break()
5656end
5757
5858t = CTask (g_break)
59- @test_throws MethodError consume (t)
59+ @test_throws Libtask . CTaskException consume (t)
You can’t perform that action at this time.
0 commit comments