InteractiveErrors.jl icon indicating copy to clipboard operation
InteractiveErrors.jl copied to clipboard

Errors coming from `show` methods are not interactive?

Open rafaqz opened this issue 3 years ago • 3 comments

When something is shown in the REPL and show throws an error, the stack trace is normal, not interactive.

rafaqz avatar May 12 '21 06:05 rafaqz

Thanks for reporting.

A reproducible error below. I assume this is what you're refering to, yes?

julia> struct T end

julia> Base.show(io::IO, ::T) = error("bad!")

julia> T()
Error showing value of type T:
ERROR: bad!
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] show(io::IOContext{Base.TTY}, #unused#::T)
    @ Main ./REPL[2]:1
  [3] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, x::T)
    @ Base.Multimedia ./multimedia.jl:47
  [4] display(d::REPL.REPLDisplay{REPL.LineEditREPL}, mime::MIME{Symbol("text/plain")}, x::T)
    @ OhMyREPL ~/.julia/packages/OhMyREPL/07uNa/src/output_prompt_overwrite.jl:8
  [5] display(d::REPL.REPLDisplay, x::Any)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:225
  [6] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:328
  [7] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
  [8] invokelatest
    @ ./essentials.jl:706 [inlined]
  [9] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:247
 [10] (::REPL.var"#40#41"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:231
 [11] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:462
 [12] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:229
 [13] (::REPL.var"#do_respond#61"{Bool, Bool, REPL.var"#72#82"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:798
 [14] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [15] invokelatest
    @ ./essentials.jl:706 [inlined]
 [16] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/LineEdit.jl:2441
 [17] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:1126
 [18] (::REPL.var"#44#49"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ./task.jl:411

julia> toggle()
false

julia> T()
Error showing value of type T:
ERROR: bad!
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] show(io::IOContext{Base.TTY}, #unused#::T)
    @ Main ./REPL[2]:1
  [3] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, x::T)
    @ Base.Multimedia ./multimedia.jl:47
  [4] display(d::REPL.REPLDisplay{REPL.LineEditREPL}, mime::MIME{Symbol("text/plain")}, x::T)
    @ OhMyREPL ~/.julia/packages/OhMyREPL/07uNa/src/output_prompt_overwrite.jl:8
  [5] display(d::REPL.REPLDisplay, x::Any)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:225
  [6] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:328
  [7] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
  [8] invokelatest
    @ ./essentials.jl:706 [inlined]
  [9] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:247
 [10] (::REPL.var"#40#41"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:231
 [11] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:462
 [12] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:229
 [13] (::REPL.var"#do_respond#61"{Bool, Bool, REPL.var"#72#82"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:798
 [14] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [15] invokelatest
    @ ./essentials.jl:706 [inlined]
 [16] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/LineEdit.jl:2441
 [17] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/usr/julia/1.6/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:1126
 [18] (::REPL.var"#44#49"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ./task.jl:411

Disabling interactive errors with toggle() doesn't appear to change the stack at all so it would appear that this isn't handled by the same code path as the rest of the error printing... You can also see that the stacktrace isn't cleaned up at all like it should, there's REPL internals printed. This may be something that's actually an upstream issue perhaps.

MichaelHatherly avatar May 12 '21 10:05 MichaelHatherly

Yep, exactly. Somehow my attrempt at a MWE was throwing an unrelated problem with display.

rafaqz avatar May 12 '21 10:05 rafaqz

Even if this could be regarded as just an upstream issue, I'd like to fix it here anyway.

MichaelHatherly avatar May 12 '21 11:05 MichaelHatherly