Skip to content

Commit 9aef639

Browse files
committed
Fix for changes in stacktrace printing
A consequence of JuliaLang/julia#36134
1 parent 6fe6760 commit 9aef639

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

src/utils.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,15 @@ function Base.show_backtrace(io::IO, frame::Frame)
654654
print(io, "\nStacktrace:")
655655
try invokelatest(Base.update_stackframes_callback[], stackframes) catch end
656656
frame_counter = 0
657-
for (last_frame, n) in stackframes
657+
nd = ndigits(length(stackframes))
658+
for (i, (last_frame, n)) in enumerate(stackframes)
658659
frame_counter += 1
659-
Base.show_trace_entry(IOContext(io, :backtrace => true), last_frame, n, prefix = string(" [", frame_counter, "] "))
660+
if isdefined(Base, :print_stackframe)
661+
println(io)
662+
Base.print_stackframe(io, i, last_frame, n, nd, Base.info_color())
663+
else
664+
Base.show_trace_entry(IOContext(io, :backtrace => true), last_frame, n, prefix = string(" [", frame_counter, "] "))
665+
end
660666
end
661667
end
662668

test/interpret.jl

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,21 @@ try
474474
frame, bp = @interpret g_1(2.0)
475475
stacktrace_lines = split(sprint(Base.display_error, bp.err, leaf(frame)), '\n')
476476
@test occursin(string("ERROR: ", sprint(showerror, ErrorException("foo"))), stacktrace_lines[1])
477-
@test occursin("[1] error(::String) at error.jl:", stacktrace_lines[3])
478-
@test occursin("[2] g_3(::Float64) at $(@__FILE__):$(line_g - 1)", stacktrace_lines[4])
479-
@test occursin("[3] g_2(::Float64) at $(@__FILE__):$(line_g - 2)", stacktrace_lines[5])
480-
@test occursin("[4] g_1(::Float64) at $(@__FILE__):$(line_g - 3)", stacktrace_lines[6])
477+
if isdefined(Base, :print_stackframe)
478+
@test occursin("[1] error(s::String)", stacktrace_lines[3])
479+
@test occursin("[2] g_3(x::Float64)", stacktrace_lines[5])
480+
thefile = Base.replaceuserpath(@__FILE__)
481+
@test occursin("$thefile:$(line_g - 1)", stacktrace_lines[6])
482+
@test occursin("[3] g_2(x::Float64)", stacktrace_lines[7])
483+
@test occursin("$thefile:$(line_g - 2)", stacktrace_lines[8])
484+
@test occursin("[4] g_1(x::Float64)", stacktrace_lines[9])
485+
@test occursin("$thefile:$(line_g - 3)", stacktrace_lines[10])
486+
else
487+
@test occursin("[1] error(::String) at error.jl:", stacktrace_lines[3])
488+
@test occursin("[2] g_3(::Float64) at $(@__FILE__):$(line_g - 1)", stacktrace_lines[4])
489+
@test occursin("[3] g_2(::Float64) at $(@__FILE__):$(line_g - 2)", stacktrace_lines[5])
490+
@test occursin("[4] g_1(::Float64) at $(@__FILE__):$(line_g - 3)", stacktrace_lines[6])
491+
end
481492
finally
482493
break_off(:error)
483494
end
@@ -492,11 +503,24 @@ try
492503
frame, bp = JuliaInterpreter.debug_command(frame, :c, true)
493504
stacktrace_lines = split(sprint(Base.display_error, bp.err, leaf(frame)), '\n')
494505
@test occursin(string("ERROR: ", sprint(showerror, ErrorException("foo"))), stacktrace_lines[1])
495-
@test occursin("[1] error(::String) at error.jl:", stacktrace_lines[3])
496-
@test occursin("[2] g_3(::Float64) at $(@__FILE__):$(line_g - 1)", stacktrace_lines[4])
497-
@test occursin("[3] g_2(::Float64) at $(@__FILE__):$(line_g - 2)", stacktrace_lines[5])
498-
@test occursin("[4] g_1(::Float64) at $(@__FILE__):$(line_g - 3)", stacktrace_lines[6])
499-
@test occursin("[5] top-level scope at $(@__FILE__):$(line2_g - 2)", stacktrace_lines[7])
506+
if isdefined(Base, :print_stackframe)
507+
@test occursin("[1] error(s::String)", stacktrace_lines[3])
508+
thefile = Base.replaceuserpath(@__FILE__)
509+
@test occursin("[2] g_3(x::Float64)", stacktrace_lines[5])
510+
@test occursin("$thefile:$(line_g - 1)", stacktrace_lines[6])
511+
@test occursin("[3] g_2(x::Float64)", stacktrace_lines[7])
512+
@test occursin("$thefile:$(line_g - 2)", stacktrace_lines[8])
513+
@test occursin("[4] g_1(x::Float64)", stacktrace_lines[9])
514+
@test occursin("$thefile:$(line_g - 3)", stacktrace_lines[10])
515+
@test occursin("[5] top-level scope", stacktrace_lines[11])
516+
@test occursin("$thefile:$(line2_g - 2)", stacktrace_lines[12])
517+
else
518+
@test occursin("[1] error(::String) at error.jl:", stacktrace_lines[3])
519+
@test occursin("[2] g_3(::Float64) at $(@__FILE__):$(line_g - 1)", stacktrace_lines[4])
520+
@test occursin("[3] g_2(::Float64) at $(@__FILE__):$(line_g - 2)", stacktrace_lines[5])
521+
@test occursin("[4] g_1(::Float64) at $(@__FILE__):$(line_g - 3)", stacktrace_lines[6])
522+
@test occursin("[5] top-level scope at $(@__FILE__):$(line2_g - 2)", stacktrace_lines[7])
523+
end
500524
finally
501525
break_off(:error)
502526
end

0 commit comments

Comments
 (0)