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
40
40
function task_wrapper (func)
41
41
() ->
42
42
try
43
- res = func ()
44
43
ct = current_task ()
44
+ res = func ()
45
45
ct. result = res
46
46
isa (ct. storage, Nothing) && (ct. storage = IdDict ())
47
47
ct. storage[:_libtask_state ] = :done
@@ -83,6 +83,20 @@ function Base.copy(t::Task)
83
83
newt
84
84
end
85
85
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
+
86
100
produce (v) = begin
87
101
ct = current_task ()
88
102
@@ -178,7 +192,12 @@ consume(p::Task, values...) = begin
178
192
return p. result
179
193
end
180
194
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))
182
201
end
183
202
end
184
203
wait ()
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ r = @testset "Broken Functions Tests" begin
17
17
try
18
18
consume (t)
19
19
catch ex
20
- @test isa (ex, ErrorException)
20
+ @test ex . etype == ErrorException
21
21
end
22
22
@test isa (t. exception, ErrorException)
23
23
end
@@ -37,7 +37,7 @@ r = @testset "Broken Functions Tests" begin
37
37
try
38
38
consume (t)
39
39
catch ex
40
- @test isa (ex, BoundsError)
40
+ @test ex . etype == BoundsError
41
41
end
42
42
@test isa (t. exception, BoundsError)
43
43
end
@@ -58,7 +58,7 @@ r = @testset "Broken Functions Tests" begin
58
58
try
59
59
consume (t)
60
60
catch ex
61
- @test isa (ex, BoundsError)
61
+ @test ex . etype == BoundsError
62
62
end
63
63
@test isa (t. exception, BoundsError)
64
64
end
@@ -80,7 +80,7 @@ r = @testset "Broken Functions Tests" begin
80
80
try
81
81
consume (t_copy)
82
82
catch ex
83
- @test isa (ex, BoundsError)
83
+ @test ex . etype == BoundsError
84
84
end
85
85
@test isa (t_copy. exception, BoundsError)
86
86
end
Original file line number Diff line number Diff line change @@ -56,4 +56,4 @@ function g_break()
56
56
end
57
57
58
58
t = 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