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

vec[nothing] fails to print its error message #30633

Closed
jamii opened this issue Jan 7, 2019 · 4 comments
Closed

vec[nothing] fails to print its error message #30633

jamii opened this issue Jan 7, 2019 · 4 comments
Labels
error handling Handling of exceptions by Julia or the user good first issue Indicates a good issue for first-time contributors to Julia

Comments

@jamii
Copy link
Contributor

jamii commented Jan 7, 2019

Expected:

julia> [1]["foo"]
ERROR: ArgumentError: invalid index: foo of type String
Stacktrace:
 [1] to_index(::String) at ./indices.jl:266
 [2] to_index(::Array{Int64,1}, ::String) at ./indices.jl:247
 [3] to_indices at ./indices.jl:294 [inlined]
 [4] to_indices at ./indices.jl:291 [inlined]
 [5] getindex(::Array{Int64,1}, ::String) at ./abstractarray.jl:905
 [6] top-level scope at none:0

Actual:

julia> [1][nothing]
ERROR: ArgumentError: `nothing` should not be printed; use `show`, `repr`, or custom output instead.
Stacktrace:
 [1] print(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Nothing) at ./show.jl:566
 [2] print_to_string(::String, ::Vararg{Any,N} where N) at ./strings/io.jl:122
 [3] string at ./strings/io.jl:155 [inlined]
 [4] to_index(::Nothing) at ./indices.jl:266
 [5] to_index(::Array{Int64,1}, ::Nothing) at ./indices.jl:247
 [6] to_indices at ./indices.jl:294 [inlined]
 [7] to_indices at ./indices.jl:291 [inlined]
 [8] getindex(::Array{Int64,1}, ::Nothing) at ./abstractarray.jl:905
 [9] top-level scope at none:0

julia> versioninfo()
Julia Version 1.0.3
Commit 099e826241 (2018-12-18 01:34 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E3-1505M v5 @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
@StefanKarpinski
Copy link
Member

Amusing. I think we should revert that change and only make interpolating nothing into Cmd objects an error since that was the original motivating case.

@KristofferC
Copy link
Member

Every time this comes up and it is fixed, it seems the end result is an improvement over the previous situation though. For example, using show correctly here would give invalid index: "foo" of type String in the case that didn't error, which is nicer.

@JeffBezanson
Copy link
Member

Agreed; this should be using show/repr for the value anyway.

@stevengj
Copy link
Member

stevengj commented Jan 9, 2019

In particular, this line should use $(repr(i, context=:limit=>true)) instead of $i.

Similarly, this line should use $(repr(I, context=:limit=>true)) instead of $I.

(The missing :limit context was also a problem since otherwise huge arrays could get dumped into the error message.)

@stevengj stevengj added error handling Handling of exceptions by Julia or the user good first issue Indicates a good issue for first-time contributors to Julia labels Jan 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error handling Handling of exceptions by Julia or the user good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

No branches or pull requests

5 participants