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

current_scope is recommended by an error message but inaccessible. #54178

Closed
LilithHafner opened this issue Apr 21, 2024 · 4 comments · Fixed by #54180
Closed

current_scope is recommended by an error message but inaccessible. #54178

LilithHafner opened this issue Apr 21, 2024 · 4 comments · Fixed by #54180
Labels
error messages Better, more actionable error messages

Comments

@LilithHafner
Copy link
Member

This is not a great UX:

julia> t = Task(() -> 4)
Task (runnable) @0x0000ffff6826d370

julia> t.scope
ERROR: Querying `scope` is disallowed. Use `current_scope` instead.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] getproperty(t::Task, field::Symbol)
   @ Base ./task.jl:184
 [3] top-level scope
   @ REPL[65]:1

julia> current_scope
ERROR: UndefVarError: `current_scope` not defined in `Main`
Suggestion: check for spelling errors or missing imports.

julia> t.current_scope
ERROR: type Task has no field current_scope
Stacktrace:
 [1] getproperty(t::Task, field::Symbol)
   @ Base ./task.jl:186
 [2] top-level scope
   @ REPL[67]:1

julia> Base.current_scope
ERROR: UndefVarError: `current_scope` not defined in `Base`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base ./Base.jl:42
 [2] top-level scope
   @ REPL[68]:1

help?> current_scope
search: current_task current_exceptions

Couldn't find current_scope
Perhaps you meant current_task
  No documentation found.

  Binding current_scope does not exist.

julia> Core.current_scope
current_scope (built-in function)

error("Querying `scope` is disallowed. Use `current_scope` instead.")

Either the error should mention that the function is internal, or it should specify how to get a public handle on that function.

The error & hint was added in #52309
cc @Keno

@Keno
Copy link
Member

Keno commented Apr 21, 2024

Core.current_scope is private, but t.scope is extra private ;)

@Keno
Copy link
Member

Keno commented Apr 21, 2024

(Because accessing t.scope would be UB if allowed)

@LilithHafner
Copy link
Member Author

Is there any public API for this? Perhaps point folks to scoped values & mention the internal Core.current_scope()?

@Keno
Copy link
Member

Keno commented Apr 21, 2024

It's an internal implementation detail of ScopedValues, although in theory a package could use it for something else, they'd just be using private APIs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Better, more actionable error messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants