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

only limit types in stack traces in the REPL #50598

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,6 @@ function show_backtrace(io::IO, t::Vector)
if haskey(io, :last_shown_line_infos)
empty!(io[:last_shown_line_infos])
end
# this will be set to true if types in the stacktrace are truncated
limitflag = Ref(false)
io = IOContext(io, :stacktrace_types_limited => limitflag)

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

Expand Down
8 changes: 3 additions & 5 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2559,14 +2559,12 @@ function show_tuple_as_call(out::IO, name::Symbol, sig::Type;
print_within_stacktrace(io, ")", bold=true)
show_method_params(io, tv)
str = String(take!(unwrapcontext(io)[1]))
if get(out, :limit, false)::Bool
typelimitflag = get(out, :stacktrace_types_limited, nothing)
if typelimitflag !== nothing
JeffBezanson marked this conversation as resolved.
Show resolved Hide resolved
sz = get(out, :displaysize, (typemax(Int), typemax(Int)))::Tuple{Int, Int}
str_lim = type_depth_limit(str, max(sz[2], 120))
if sizeof(str_lim) < sizeof(str)
typelimitflag = get(out, :stacktrace_types_limited, nothing)
if typelimitflag !== nothing
typelimitflag[] = true
end
typelimitflag[] = true
end
str = str_lim
end
Expand Down
17 changes: 15 additions & 2 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ function print_response(repl::AbstractREPL, response, show_value::Bool, have_col
end
return nothing
end

function repl_display_error(errio::IO, @nospecialize errval)
# this will be set to true if types in the stacktrace are truncated
limitflag = Ref(false)
errio = IOContext(errio, :stacktrace_types_limited => limitflag)
Base.invokelatest(Base.display_error, errio, errval)
if limitflag[]
print(errio, "Some type information was truncated. Use `show(err)` to see complete types.")
println(errio)
end
return nothing
end

function print_response(errio::IO, response, show_value::Bool, have_color::Bool, specialdisplay::Union{AbstractDisplay,Nothing}=nothing)
Base.sigatomic_begin()
val, iserr = response
Expand All @@ -292,7 +305,7 @@ function print_response(errio::IO, response, show_value::Bool, have_color::Bool,
if iserr
val = Base.scrub_repl_backtrace(val)
Base.istrivialerror(val) || setglobal!(Base.MainInclude, :err, val)
Base.invokelatest(Base.display_error, errio, val)
repl_display_error(errio, val)
else
if val !== nothing && show_value
try
Expand All @@ -315,7 +328,7 @@ function print_response(errio::IO, response, show_value::Bool, have_color::Bool,
try
excs = Base.scrub_repl_backtrace(current_exceptions())
setglobal!(Base.MainInclude, :err, excs)
Base.invokelatest(Base.display_error, errio, excs)
repl_display_error(errio, excs)
catch e
# at this point, only print the name of the type as a Symbol to
# minimize the possibility of further errors.
Expand Down
11 changes: 11 additions & 0 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1659,3 +1659,14 @@ fake_repl() do stdin_write, stdout_read, repl
write(stdin_write, '\x04')
Base.wait(repltask)
end

fake_repl() do stdin_write, stdout_read, repl
backend = REPL.REPLBackend()
repltask = @async REPL.run_repl(repl; backend)
write(stdin_write,
"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")
txt = readuntil(stdout_read, "ZZZZZ")
write(stdin_write, '\x04')
wait(repltask)
@test contains(txt, "Some type information was truncated. Use `show(err)` to see complete types.")
end
1 change: 0 additions & 1 deletion test/stacktraces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ struct F49231{a,b,c,d,e,f,g} end
stacktrace(catch_backtrace())
end
str = sprint(Base.show_backtrace, st, context = (:limit=>true, :color=>true, :displaysize=>(50,105)))
@test endswith(str, "to see complete types.")
@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")

st = try
Expand Down