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

err variable trashes global #48299

Closed
laurentbartholdi opened this issue Jan 16, 2023 · 2 comments · Fixed by #48308
Closed

err variable trashes global #48299

laurentbartholdi opened this issue Jan 16, 2023 · 2 comments · Fixed by #48308

Comments

@laurentbartholdi
Copy link
Contributor

I just discovered the @enum macro, which I love, but does some wrong error handling.

julia> versioninfo()
Julia Version 1.10.0-DEV.343
Commit a526a4a4b3 (2023-01-11 15:23 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin22.2.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
  Threads: 1 on 8 virtual cores

julia> @enum A test

julia> err = "my precious data"
"my precious data"

julia> @enum A::Bool test2
ERROR: invalid redefinition of constant Main.A
Stacktrace:
 [1] top-level scope
   @ Enums.jl:201
 [2] top-level scope
   @ REPL[4]:1

julia> err
1-element ExceptionStack:
invalid redefinition of constant Main.A
Stacktrace:
 [1] top-level scope
   @ Enums.jl:201
 [2] top-level scope
   @ REPL[4]:1
@martinholters
Copy link
Member

Has nothing to do with @enum AFAICT. If an exception reaches the REPL, it is put in err.

@Seelengrab
Copy link
Contributor

Correct - though it should get some documentation, which ans has:

help?> ans
search: ans transpose transcode contains expanduser instances MathConstants readlines LinearIndices leading_ones

  ans

  A variable referring to the last computed value, automatically set at the interactive prompt.

help?> err
search: error errormonitor ErrorException @error stderr InterruptException showerror LoadError InitError

Couldn't find err
Perhaps you meant error, zero, repr, eof, eps, esc, exp, end, nor, rm, xor, Ptr, for, try, @error, stderr or merge
  No documentation found.

  Binding err does not exist.

julia> error("Last Error")
ERROR: Last Error
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] top-level scope
   @ REPL[3]:1

julia> err
1-element ExceptionStack:
Last Error
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] top-level scope
   @ REPL[3]:1

julia> err[1]
(exception = ErrorException("Last Error"), backtrace = Base.StackTraces.StackFrame[error(s::String) at error.jl:35, top-level scope at REPL[3]:1])

vtjnash added a commit to vtjnash/julia that referenced this issue Jan 16, 2023
This hides them from `names()` unfortunately, but means we will not
accidentally discard a variable from the user in Main, either because
the import will fail or the assignment will fail. If we later have
world-versioned bindings, this would also mean you could toggle (between
worlds) between being module-local and a special import value.

Fix JuliaLang#43172
Fix JuliaLang#48299
vtjnash added a commit to vtjnash/julia that referenced this issue Feb 14, 2023
This hides them from `names()` unfortunately, but means we will not
accidentally discard a variable from the user in Main, either because
the import will fail or the assignment will fail. If we later have
world-versioned bindings, this would also mean you could toggle (between
worlds) between being module-local and a special import value.

This also needed some improvements to docs, so that it would print
docstrings for unassigned globals without also simultaneously claiming
that it did not exist.

Fix JuliaLang#43172
Fix JuliaLang#48299
vtjnash added a commit that referenced this issue Feb 15, 2023
This hides them from `names()` unfortunately, but means we will not
accidentally discard a variable from the user in Main, either because
the import will fail or the assignment will fail. If we later have
world-versioned bindings, this would also mean you could toggle (between
worlds) between being module-local and a special import value.

This also needed some improvements to docs, so that it would print
docstrings for unassigned globals without also simultaneously claiming
that it did not exist.

Fix #43172
Fix #48299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants