Skip to content

Commit dd3e37d

Browse files
committed
only print show(err) suggestion for limited types in REPL
fixes #50575
1 parent 0f56da8 commit dd3e37d

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

base/errorshow.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,6 @@ function show_backtrace(io::IO, t::Vector)
772772
if haskey(io, :last_shown_line_infos)
773773
empty!(io[:last_shown_line_infos])
774774
end
775-
# this will be set to true if types in the stacktrace are truncated
776-
limitflag = Ref(false)
777-
io = IOContext(io, :stacktrace_types_limited => limitflag)
778775

779776
# t is a pre-processed backtrace (ref #12856)
780777
if t isa Vector{Any}
@@ -800,9 +797,6 @@ function show_backtrace(io::IO, t::Vector)
800797
# process_backtrace returns a Vector{Tuple{Frame, Int}}
801798
show_full_backtrace(io, filtered; print_linebreaks = stacktrace_linebreaks())
802799
end
803-
if limitflag[]
804-
print(io, "\nSome type information was truncated. Use `show(err)` to see complete types.")
805-
end
806800
nothing
807801
end
808802

stdlib/REPL/src/REPL.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,19 @@ function print_response(repl::AbstractREPL, response, show_value::Bool, have_col
283283
end
284284
return nothing
285285
end
286+
287+
function repl_display_error(errio::IO, @nospecialize errval)
288+
# this will be set to true if types in the stacktrace are truncated
289+
limitflag = Ref(false)
290+
errio = IOContext(errio, :stacktrace_types_limited => limitflag)
291+
Base.invokelatest(Base.display_error, errio, errval)
292+
if limitflag[]
293+
print(errio, "Some type information was truncated. Use `show(err)` to see complete types.")
294+
println(errio)
295+
end
296+
return nothing
297+
end
298+
286299
function print_response(errio::IO, response, show_value::Bool, have_color::Bool, specialdisplay::Union{AbstractDisplay,Nothing}=nothing)
287300
Base.sigatomic_begin()
288301
val, iserr = response
@@ -292,7 +305,7 @@ function print_response(errio::IO, response, show_value::Bool, have_color::Bool,
292305
if iserr
293306
val = Base.scrub_repl_backtrace(val)
294307
Base.istrivialerror(val) || setglobal!(Base.MainInclude, :err, val)
295-
Base.invokelatest(Base.display_error, errio, val)
308+
repl_display_error(errio, val)
296309
else
297310
if val !== nothing && show_value
298311
try
@@ -315,7 +328,7 @@ function print_response(errio::IO, response, show_value::Bool, have_color::Bool,
315328
try
316329
excs = Base.scrub_repl_backtrace(current_exceptions())
317330
setglobal!(Base.MainInclude, :err, excs)
318-
Base.invokelatest(Base.display_error, errio, excs)
331+
repl_display_error(errio, excs)
319332
catch e
320333
# at this point, only print the name of the type as a Symbol to
321334
# minimize the possibility of further errors.

stdlib/REPL/test/repl.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,3 +1659,14 @@ fake_repl() do stdin_write, stdout_read, repl
16591659
write(stdin_write, '\x04')
16601660
Base.wait(repltask)
16611661
end
1662+
1663+
fake_repl() do stdin_write, stdout_read, repl
1664+
backend = REPL.REPLBackend()
1665+
repltask = @async REPL.run_repl(repl; backend)
1666+
write(stdin_write,
1667+
"a = UInt8(81):UInt8(160); b = view(a, 1:64); c = reshape(b, (8, 8)); d = reinterpret(reshape, Float64, c); sqrteach(a) = [sqrt(x) for x in a]; sqrteach(d)\n\"ZZZZZ\"\n")
1668+
txt = readuntil(stdout_read, "ZZZZZ")
1669+
write(stdin_write, '\x04')
1670+
wait(repltask)
1671+
@test contains(txt, "Some type information was truncated. Use `show(err)` to see complete types.")
1672+
end

test/stacktraces.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ struct F49231{a,b,c,d,e,f,g} end
235235
stacktrace(catch_backtrace())
236236
end
237237
str = sprint(Base.show_backtrace, st, context = (:limit=>true, :color=>true, :displaysize=>(50,105)))
238-
@test endswith(str, "to see complete types.")
239238
@test contains(str, "[5] \e[0m\e[1mcollect_to!\e[22m\e[0m\e[1m(\e[22m\e[90mdest\e[39m::\e[0mVector\e[90m{…}\e[39m, \e[90mitr\e[39m::\e[0mBase.Generator\e[90m{…}\e[39m, \e[90moffs\e[39m::\e[0m$Int, \e[90mst\e[39m::\e[0mTuple\e[90m{…}\e[39m\e[0m\e[1m)\e[22m\n\e[90m")
240239

241240
st = try

0 commit comments

Comments
 (0)