@@ -638,14 +638,16 @@ const update_stackframes_callback = Ref{Function}(identity)
638638const STACKTRACE_MODULECOLORS = Iterators. Stateful (Iterators. cycle ([:magenta , :cyan , :green , :yellow ]))
639639const STACKTRACE_FIXEDCOLORS = IdDict (Base => :light_black , Core => :light_black )
640640
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 )
642642 num_frames = length (trace)
643643 ndigits_max = ndigits (num_frames)
644644
645- println (io, " \n Stacktrace:" )
645+ println (io)
646+ prefix === nothing || print (io, prefix)
647+ println (io, " Stacktrace:" )
646648
647649 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 )
649651 if i < num_frames
650652 println (io)
651653 print_linebreaks && println (io)
655657
656658const BIG_STACKTRACE_SIZE = 50 # Arbitrary constant chosen here
657659
658- function show_reduced_backtrace (io:: IO , t:: Vector )
660+ function show_reduced_backtrace (io:: IO , t:: Vector ; prefix = nothing )
659661 recorded_positions = IdDict {UInt, Vector{Int}} ()
660662 #= For each frame of hash h, recorded_positions[h] is the list of indices i
661663 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)
701703
702704 try invokelatest (update_stackframes_callback[], displayed_stackframes) catch end
703705
704- println (io, " \n Stacktrace:" )
706+ println (io)
707+ prefix === nothing || print (io, prefix)
708+ println (io, " Stacktrace:" )
705709
706710 ndigits_max = ndigits (length (t))
707711
708712 push! (repeated_cycle, (0 ,0 ,0 )) # repeated_cycle is never empty
709713 frame_counter = 1
710714 for i in eachindex (displayed_stackframes)
711715 (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 )
714718
715719 if i < length (displayed_stackframes)
716720 println (io)
@@ -721,6 +725,7 @@ function show_reduced_backtrace(io::IO, t::Vector)
721725 cycle_length = repeated_cycle[1 ][2 ]
722726 repetitions = repeated_cycle[1 ][3 ]
723727 popfirst! (repeated_cycle)
728+ prefix === nothing || print (io, prefix)
724729 printstyled (io,
725730 " --- the above " , cycle_length, " lines are repeated " ,
726731 repetitions, " more time" , repetitions> 1 ? " s" : " " , " ---" , color = :light_black )
@@ -738,15 +743,15 @@ end
738743# Print a stack frame where the module color is determined by looking up the parent module in
739744# `modulecolordict`. If the module does not have a color, yet, a new one can be drawn
740745# 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 )
742747 m = Base. parentmodule (frame)
743748 modulecolor = if m != = nothing
744749 m = parentmodule_before_main (m)
745750 get! (() -> popfirst! (modulecolorcycler), modulecolordict, m)
746751 else
747752 :default
748753 end
749- print_stackframe (io, i, frame, n, ndigits_max, modulecolor)
754+ print_stackframe (io, i, frame, n, ndigits_max, modulecolor; prefix )
750755end
751756
752757# Gets the topmost parent module that isn't Main
761766parentmodule_before_main (x) = parentmodule_before_main (parentmodule (x))
762767
763768# 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 )
765770 file, line = string (frame. file), frame. line
766771
767772 # 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
776781 digit_align_width = ndigits_max + 2
777782
778783 # frame number
784+ prefix === nothing || print (io, prefix)
779785 print (io, " " , lpad (" [" * string (i) * " ]" , digit_align_width))
780786 print (io, " " )
781787
@@ -785,6 +791,7 @@ function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulec
785791 end
786792 println (io)
787793
794+ prefix === nothing || print (io, prefix)
788795 # @ Module path / file : line
789796 print_module_path_file (io, modul, file, line; modulecolor, digit_align_width)
790797
@@ -813,7 +820,7 @@ function print_module_path_file(io, modul, file, line; modulecolor = :light_blac
813820 printstyled (io, basename (file), " :" , line; color = :light_black , underline = true )
814821end
815822
816- function show_backtrace (io:: IO , t:: Vector )
823+ function show_backtrace (io:: IO , t:: Vector ; prefix = nothing )
817824 if haskey (io, :last_shown_line_infos )
818825 empty! (io[:last_shown_line_infos ])
819826 end
@@ -835,12 +842,12 @@ function show_backtrace(io::IO, t::Vector)
835842 end
836843
837844 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 )
839846 return
840847 else
841848 try invokelatest (update_stackframes_callback[], filtered) catch end
842849 # 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 )
844851 end
845852 nothing
846853end
0 commit comments