Skip to content

Reverse stacktrace display order #52430

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,13 @@ istrivialerror(stack::ExceptionStack) =
# frame 1 = top level; assumes already went through scrub_repl_backtrace; MethodError see #50803

function display_error(io::IO, stack::ExceptionStack)
printstyled(io, "ERROR: "; bold=true, color=Base.error_color())
show_exception_stack(IOContext(io, :limit => true), stack)
println(io)
end
display_error(stack::ExceptionStack) = display_error(stderr, stack)

# these forms are depended on by packages outside Julia
function display_error(io::IO, er, bt)
printstyled(io, "ERROR: "; bold=true, color=Base.error_color())
showerror(IOContext(io, :limit => true), er, bt, backtrace = bt!==nothing)
println(io)
end
Expand Down
23 changes: 10 additions & 13 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ end

function showerror(io::IO, ex, bt; backtrace=true)
try
showerror(io, ex)
finally
backtrace && show_backtrace(io, bt)
finally
printstyled(io, "\nERROR: "; bold=true, color=Base.error_color())
showerror(io, ex)
end
end

Expand Down Expand Up @@ -613,10 +614,10 @@ function show_full_backtrace(io::IO, trace::Vector; print_linebreaks::Bool)
num_frames = length(trace)
ndigits_max = ndigits(num_frames)

println(io, "\nStacktrace:")
println(io, "Stacktrace:")

for (i, (frame, n)) in enumerate(trace)
print_stackframe(io, i, frame, n, ndigits_max, STACKTRACE_FIXEDCOLORS, STACKTRACE_MODULECOLORS)
print_stackframe(io, length(trace)+1-i, frame, n, ndigits_max, STACKTRACE_FIXEDCOLORS, STACKTRACE_MODULECOLORS)
if i < num_frames
println(io)
print_linebreaks && println(io)
Expand Down Expand Up @@ -672,12 +673,12 @@ function show_reduced_backtrace(io::IO, t::Vector)

try invokelatest(update_stackframes_callback[], displayed_stackframes) catch end

println(io, "\nStacktrace:")
println(io, "Stacktrace:")

ndigits_max = ndigits(length(t))

push!(repeated_cycle, (0,0,0)) # repeated_cycle is never empty
frame_counter = 1
frame_counter = length(t)-1
for i in 1:length(displayed_stackframes)
(frame, n) = displayed_stackframes[i]

Expand All @@ -699,9 +700,9 @@ function show_reduced_backtrace(io::IO, t::Vector)
println(io)
stacktrace_linebreaks() && println(io)
end
frame_counter += cycle_length * repetitions
frame_counter -= cycle_length * repetitions
end
frame_counter += 1
frame_counter -= 1
end
end

Expand Down Expand Up @@ -790,11 +791,7 @@ function show_backtrace(io::IO, t::Vector)
end

# t is a pre-processed backtrace (ref #12856)
if t isa Vector{Any}
filtered = t
else
filtered = process_backtrace(t)
end
filtered = reverse(t isa Vector{Any} ? t : process_backtrace(t))
isempty(filtered) && return

if length(filtered) == 1 && StackTraces.is_top_level_frame(filtered[1][1])
Expand Down