Skip to content

Commit

Permalink
Better error message for task.scope (#54180)
Browse files Browse the repository at this point in the history
Fixes #54178
  • Loading branch information
LilithHafner authored Apr 23, 2024
1 parent 435ba8f commit 53f452a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ end
# TODO: this field name should be deprecated in 2.0
return t._isexception ? t.result : nothing
elseif field === :scope
error("Querying `scope` is disallowed. Use `current_scope` instead.")
error("""
Querying a Task's `scope` field is disallowed.
The private `Core.current_scope()` function is better, though still an implementation detail.""")
else
return getfield(t, field)
end
Expand Down
3 changes: 2 additions & 1 deletion test/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ end
@testset "Task properties" begin
f() = rand(2,2)
t = Task(f)
@test_throws ErrorException("Querying `scope` is disallowed. Use `current_scope` instead.") t.scope
message = "Querying a Task's `scope` field is disallowed.\nThe private `Core.current_scope()` function is better, though still an implementation detail."
@test_throws ErrorException(message) t.scope
@test t.state == :runnable
end

0 comments on commit 53f452a

Please sign in to comment.