@@ -638,14 +638,16 @@ const update_stackframes_callback = Ref{Function}(identity)
638
638
const STACKTRACE_MODULECOLORS = Iterators. Stateful (Iterators. cycle ([:magenta , :cyan , :green , :yellow ]))
639
639
const STACKTRACE_FIXEDCOLORS = IdDict (Base => :light_black , Core => :light_black )
640
640
641
- function show_full_backtrace (io:: IO , trace:: Vector ; print_linebreaks:: Bool )
641
+ function show_full_backtrace (io:: IO , trace:: Vector ; print_linebreaks:: Bool , prefix = nothing )
642
642
num_frames = length (trace)
643
643
ndigits_max = ndigits (num_frames)
644
644
645
- println (io, " \n Stacktrace:" )
645
+ println (io)
646
+ prefix === nothing || print (io, prefix)
647
+ println (io, " Stacktrace:" )
646
648
647
649
for (i, (frame, n)) in enumerate (trace)
648
- print_stackframe (io, i, frame, n, ndigits_max, STACKTRACE_FIXEDCOLORS, STACKTRACE_MODULECOLORS)
650
+ print_stackframe (io, i, frame, n, ndigits_max, STACKTRACE_FIXEDCOLORS, STACKTRACE_MODULECOLORS; prefix )
649
651
if i < num_frames
650
652
println (io)
651
653
print_linebreaks && println (io)
655
657
656
658
const BIG_STACKTRACE_SIZE = 50 # Arbitrary constant chosen here
657
659
658
- function show_reduced_backtrace (io:: IO , t:: Vector )
660
+ function show_reduced_backtrace (io:: IO , t:: Vector ; prefix = nothing )
659
661
recorded_positions = IdDict {UInt, Vector{Int}} ()
660
662
#= For each frame of hash h, recorded_positions[h] is the list of indices i
661
663
such that hash(t[i-1]) == h, ie the list of positions in which the
@@ -701,16 +703,18 @@ function show_reduced_backtrace(io::IO, t::Vector)
701
703
702
704
try invokelatest (update_stackframes_callback[], displayed_stackframes) catch end
703
705
704
- println (io, " \n Stacktrace:" )
706
+ println (io)
707
+ prefix === nothing || print (io, prefix)
708
+ println (io, " Stacktrace:" )
705
709
706
710
ndigits_max = ndigits (length (t))
707
711
708
712
push! (repeated_cycle, (0 ,0 ,0 )) # repeated_cycle is never empty
709
713
frame_counter = 1
710
714
for i in eachindex (displayed_stackframes)
711
715
(frame, n) = displayed_stackframes[i]
712
-
713
- print_stackframe (io, frame_counter, frame, n, ndigits_max, STACKTRACE_FIXEDCOLORS, STACKTRACE_MODULECOLORS)
716
+ prefix === nothing || print (io, prefix)
717
+ print_stackframe (io, frame_counter, frame, n, ndigits_max, STACKTRACE_FIXEDCOLORS, STACKTRACE_MODULECOLORS; prefix )
714
718
715
719
if i < length (displayed_stackframes)
716
720
println (io)
@@ -721,6 +725,7 @@ function show_reduced_backtrace(io::IO, t::Vector)
721
725
cycle_length = repeated_cycle[1 ][2 ]
722
726
repetitions = repeated_cycle[1 ][3 ]
723
727
popfirst! (repeated_cycle)
728
+ prefix === nothing || print (io, prefix)
724
729
printstyled (io,
725
730
" --- the above " , cycle_length, " lines are repeated " ,
726
731
repetitions, " more time" , repetitions> 1 ? " s" : " " , " ---" , color = :light_black )
@@ -738,15 +743,15 @@ end
738
743
# Print a stack frame where the module color is determined by looking up the parent module in
739
744
# `modulecolordict`. If the module does not have a color, yet, a new one can be drawn
740
745
# from `modulecolorcycler`.
741
- function print_stackframe (io, i, frame:: StackFrame , n:: Int , ndigits_max, modulecolordict, modulecolorcycler)
746
+ function print_stackframe (io, i, frame:: StackFrame , n:: Int , ndigits_max, modulecolordict, modulecolorcycler; prefix = nothing )
742
747
m = Base. parentmodule (frame)
743
748
modulecolor = if m != = nothing
744
749
m = parentmodule_before_main (m)
745
750
get! (() -> popfirst! (modulecolorcycler), modulecolordict, m)
746
751
else
747
752
:default
748
753
end
749
- print_stackframe (io, i, frame, n, ndigits_max, modulecolor)
754
+ print_stackframe (io, i, frame, n, ndigits_max, modulecolor; prefix )
750
755
end
751
756
752
757
# Gets the topmost parent module that isn't Main
761
766
parentmodule_before_main (x) = parentmodule_before_main (parentmodule (x))
762
767
763
768
# Print a stack frame where the module color is set manually with `modulecolor`.
764
- function print_stackframe (io, i, frame:: StackFrame , n:: Int , ndigits_max, modulecolor)
769
+ function print_stackframe (io, i, frame:: StackFrame , n:: Int , ndigits_max, modulecolor; prefix = nothing )
765
770
file, line = string (frame. file), frame. line
766
771
767
772
# Used by the REPL to make it possible to open
@@ -776,6 +781,7 @@ function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulec
776
781
digit_align_width = ndigits_max + 2
777
782
778
783
# frame number
784
+ prefix === nothing || print (io, prefix)
779
785
print (io, " " , lpad (" [" * string (i) * " ]" , digit_align_width))
780
786
print (io, " " )
781
787
@@ -785,6 +791,7 @@ function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulec
785
791
end
786
792
println (io)
787
793
794
+ prefix === nothing || print (io, prefix)
788
795
# @ Module path / file : line
789
796
print_module_path_file (io, modul, file, line; modulecolor, digit_align_width)
790
797
@@ -813,7 +820,7 @@ function print_module_path_file(io, modul, file, line; modulecolor = :light_blac
813
820
printstyled (io, basename (file), " :" , line; color = :light_black , underline = true )
814
821
end
815
822
816
- function show_backtrace (io:: IO , t:: Vector )
823
+ function show_backtrace (io:: IO , t:: Vector ; prefix = nothing )
817
824
if haskey (io, :last_shown_line_infos )
818
825
empty! (io[:last_shown_line_infos ])
819
826
end
@@ -835,12 +842,12 @@ function show_backtrace(io::IO, t::Vector)
835
842
end
836
843
837
844
if length (filtered) > BIG_STACKTRACE_SIZE
838
- show_reduced_backtrace (IOContext (io, :backtrace => true ), filtered)
845
+ show_reduced_backtrace (IOContext (io, :backtrace => true ), filtered; prefix )
839
846
return
840
847
else
841
848
try invokelatest (update_stackframes_callback[], filtered) catch end
842
849
# process_backtrace returns a Vector{Tuple{Frame, Int}}
843
- show_full_backtrace (io, filtered; print_linebreaks = stacktrace_linebreaks ())
850
+ show_full_backtrace (io, filtered; print_linebreaks = stacktrace_linebreaks (), prefix )
844
851
end
845
852
nothing
846
853
end
0 commit comments