Skip to content
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

Show full stacktrace when Channel Task throws #35177

Merged
merged 2 commits into from
Apr 30, 2020
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
11 changes: 6 additions & 5 deletions base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,16 @@ false
```jldoctest
julia> c = Channel(0);

julia> task = @async (put!(c,1);error("foo"));
julia> task = @async (put!(c, 1); error("foo"));

julia> bind(c,task);
julia> bind(c, task);

julia> take!(c)
1

julia> put!(c,1);
ERROR: foo
julia> put!(c, 1);
ERROR: TaskFailedException:
foo
Stacktrace:
[...]
```
Expand Down Expand Up @@ -281,7 +282,7 @@ function close_chnl_on_taskdone(t::Task, c::Channel)
if istaskfailed(t)
excp = task_result(t)
if excp isa Exception
close(c, excp)
close(c, TaskFailedException(t))
return
end
end
Expand Down
18 changes: 10 additions & 8 deletions test/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ using Distributed

# Error exception in task
c = Channel(N)
bind(c, @async (GC.gc(); yield(); error("foo")))
@test_throws ErrorException take!(c)
task = @async (GC.gc(); yield(); error("foo"))
bind(c, task)
@test_throws TaskFailedException(task) take!(c)
@test !isopen(c)

# Multiple channels closed by the same bound task
Expand All @@ -170,10 +171,11 @@ using Distributed
while isopen(cs[i])
yield()
end
@test_throws ErrorException wait(cs[i])
@test_throws ErrorException take!(cs[i])
@test_throws ErrorException put!(cs[i], 1)
@test_throws ErrorException fetch(cs[i])
@test_throws TaskFailedException(task) wait(cs[i])
@test_throws TaskFailedException(task) take!(cs[i])
@test_throws TaskFailedException(task) put!(cs[i], 1)
N == 0 || @test_throws TaskFailedException(task) fetch(cs[i])
N == 0 && @test_throws ErrorException fetch(cs[i])
end

# Multiple tasks, first one to terminate closes the channel
Expand Down Expand Up @@ -245,10 +247,10 @@ using Distributed
chnl = Channel{T}(tf6, N, taskref=taskref)
put!(chnl, 2)
yield()
@test_throws ErrorException wait(chnl)
@test_throws TaskFailedException(taskref[]) wait(chnl)
@test istaskdone(taskref[])
@test !isopen(chnl)
@test_throws ErrorException take!(chnl)
@test_throws TaskFailedException(taskref[]) take!(chnl)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ cd(dirwalk) do
@test files == ["file1", "file2"]

rm(joinpath("sub_dir1"), recursive=true)
@test_throws SystemError take!(chnl_error) # throws an error because sub_dir1 do not exist
@test_throws TaskFailedException take!(chnl_error) # throws an error because sub_dir1 do not exist

root, dirs, files = take!(chnl_noerror)
@test root == "."
Expand Down
2 changes: 1 addition & 1 deletion test/worlds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ f265(::Int) = 1
h265() = true
loc_h265 = "$(@__FILE__):$(@__LINE__() - 1)"
@test h265()
@test_throws MethodError put_n_take!(h265, ())
@test_throws TaskFailedException(t265) put_n_take!(h265, ())
@test_throws TaskFailedException(t265) fetch(t265)
@test istaskdone(t265)
let ex = t265.exception
Expand Down