Julia 1.6 Stacktrace

For some sort of workaround, you can put this in your .julia/config/startup.jl file and tweak the color of the paths on the second line:

@eval Base begin

path_color = :red

function print_stackframe(io, i, frame::StackFrame, n::Int, digit_align_width, modulecolor)
    file, line = string(frame.file), frame.line
    stacktrace_expand_basepaths() && (file = something(find_source_file(file), file))
    stacktrace_contract_userdir() && (file = replaceuserpath(file))

    # Used by the REPL to make it possible to open
    # the location of a stackframe/method in the editor.
    if haskey(io, :last_shown_line_infos)
        push!(io[:last_shown_line_infos], (string(frame.file), frame.line))
    end

    inlined = getfield(frame, :inlined)
    modul = parentmodule(frame)

    # frame number
    print(io, " ", lpad("[" * string(i) * "]", digit_align_width + 2))
    print(io, " ")

    StackTraces.show_spec_linfo(IOContext(io, :backtrace=>true), frame)
    if n > 1
        printstyled(io, " (repeats $n times)"; color=:light_black)
    end
    println(io)

    # @
    printstyled(io, " " ^ (digit_align_width + 2) * "@ ", color = :light_black)

    # module
    if modul !== nothing
        printstyled(io, modul, color = modulecolor)
        print(io, " ")
    end

    # filepath
    pathparts = splitpath(file)
    folderparts = pathparts[1:end-1]
    if !isempty(folderparts)
        printstyled(io, joinpath(folderparts...) * (Sys.iswindows() ? "\\" : "/"), color = path_color)
    end

    # filename, separator, line
    # use escape codes for formatting, printstyled can't do underlined and color
    # codes are bright black (90) and underlined (4)
    function print_underlined(io::IO, s...)
        colored = get(io, :color, false)::Bool
        start_s = colored ? text_colors[path_color] * "\033[4m" : ""
        end_s   = colored ? "\033[0m"    : ""
        print(io, start_s, s..., end_s)
    end
    print_underlined(io, pathparts[end], ":", line)

    # inlined
    printstyled(io, inlined ? " [inlined]" : "", color = path_color)
end

end

12 Likes