@@ -371,6 +371,20 @@ function showerror_nostdio(err, msg::AbstractString)
371371 ccall (:jl_printf , Cint, (Ptr{Cvoid},Cstring), stderr_stream, " \n " )
372372end
373373
374+ stacktrace_expand_basepaths ():: Bool =
375+ tryparse (Bool, get (ENV , " JULIA_STACKTRACE_EXPAND_BASEPATHS" , " false" )) === true
376+ stacktrace_contract_userdir ():: Bool =
377+ tryparse (Bool, get (ENV , " JULIA_STACKTRACE_CONTRACT_HOMEDIR" , " true" )) === true
378+ stacktrace_linebreaks ():: Bool =
379+ tryparse (Bool, get (ENV , " JULIA_STACKTRACE_LINEBREAKS" , " false" )) === true
380+
381+ function replaceuserpath (str:: String )
382+ str = replace (str, homedir () => " ~" )
383+ # seems to be necessary for some paths with small letter drive c:// etc
384+ str = replace (str, lowercasefirst (homedir ()) => " ~" )
385+ return str
386+ end
387+
374388function show_method_candidates (io:: IO , ex:: MethodError , @nospecialize kwargs= ())
375389 is_arg_types = isa (ex. args, DataType)
376390 arg_types = is_arg_types ? ex. args : typesof (ex. args... )
@@ -498,7 +512,12 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
498512 end
499513 print (iob, " )" )
500514 show_method_params (iob0, tv)
501- print (iob, " at " , method. file, " :" , method. line)
515+ file, line = functionloc (method)
516+ if file === nothing
517+ file = string (method. file)
518+ end
519+ stacktrace_contract_userdir () && (file = replaceuserpath (file))
520+ print (iob, " at " , file, " :" , line)
502521 if ! isempty (kwargs):: Bool
503522 unexpected = Symbol[]
504523 if isempty (kwords) || ! (any (endswith (string (kword), " ..." ) for kword in kwords))
555574# replace `sf` as needed.
556575const update_stackframes_callback = Ref {Function} (identity)
557576
558- function replaceuserpath (str)
559- str = replace (str, homedir () => " ~" )
560- # seems to be necessary for some paths with small letter drive c:// etc
561- str = replace (str, lowercasefirst (homedir ()) => " ~" )
562- return str
563- end
564-
565577const STACKTRACE_MODULECOLORS = [:light_blue , :light_yellow ,
566578 :light_magenta , :light_green , :light_cyan , :light_red ,
567579 :blue , :yellow , :magenta , :green , :cyan , :red ]
568- stacktrace_expand_basepaths ():: Bool =
569- tryparse (Bool, get (ENV , " JULIA_STACKTRACE_EXPAND_BASEPATHS" , " false" )) === true
570- stacktrace_contract_userdir ():: Bool =
571- tryparse (Bool, get (ENV , " JULIA_STACKTRACE_CONTRACT_HOMEDIR" , " true" )) === true
572- stacktrace_linebreaks ():: Bool =
573- tryparse (Bool, get (ENV , " JULIA_STACKTRACE_LINEBREAKS" , " false" )) === true
574580
575581function show_full_backtrace (io:: IO , trace:: Vector ; print_linebreaks:: Bool )
576582 n = length (trace)
700706# Print a stack frame where the module color is set manually with `modulecolor`.
701707function print_stackframe (io, i, frame, n, digit_align_width, modulecolor)
702708 file, line = string (frame. file), frame. line
709+ file = updated_methodfile (file)
703710 stacktrace_expand_basepaths () && (file = something (find_source_file (file), file))
704711 stacktrace_contract_userdir () && (file = replaceuserpath (file))
705712
0 commit comments