Skip to content

Commit 12b9178

Browse files
committed
fix some issues with buildbot path not updating in stacktraces / method errors (#37427)
(cherry picked from commit 1217aa4)
1 parent 97e65d3 commit 12b9178

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

base/errorshow.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ function showerror_nostdio(err, msg::AbstractString)
362362
ccall(:jl_printf, Cint, (Ptr{Cvoid},Cstring), stderr_stream, "\n")
363363
end
364364

365+
stacktrace_expand_basepaths()::Bool =
366+
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_EXPAND_BASEPATHS", "false")) === true
367+
stacktrace_contract_userdir()::Bool =
368+
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_CONTRACT_HOMEDIR", "true")) === true
369+
stacktrace_linebreaks()::Bool =
370+
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_LINEBREAKS", "false")) === true
371+
365372
function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=())
366373
is_arg_types = isa(ex.args, DataType)
367374
arg_types = is_arg_types ? ex.args : typesof(ex.args...)
@@ -489,7 +496,12 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
489496
end
490497
print(iob, ")")
491498
show_method_params(iob0, tv)
492-
print(iob, " at ", method.file, ":", method.line)
499+
file, line = functionloc(method)
500+
if file === nothing
501+
file = string(method.file)
502+
end
503+
stacktrace_contract_userdir() && (file = contractuser(file))
504+
print(iob, " at ", file, ":", line)
493505
if !isempty(kwargs)::Bool
494506
unexpected = Symbol[]
495507
if isempty(kwords) || !(any(endswith(string(kword), "...") for kword in kwords))
@@ -549,13 +561,6 @@ const update_stackframes_callback = Ref{Function}(identity)
549561
const STACKTRACE_MODULECOLORS = [:magenta, :cyan, :green, :yellow]
550562
const STACKTRACE_FIXEDCOLORS = IdDict(Base => :light_black, Core => :light_black)
551563

552-
stacktrace_expand_basepaths()::Bool =
553-
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_EXPAND_BASEPATHS", "false")) === true
554-
stacktrace_contract_userdir()::Bool =
555-
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_CONTRACT_HOMEDIR", "true")) === true
556-
stacktrace_linebreaks()::Bool =
557-
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_LINEBREAKS", "false")) === true
558-
559564
function show_full_backtrace(io::IO, trace::Vector; print_linebreaks::Bool)
560565
num_frames = length(trace)
561566
ndigits_max = ndigits(num_frames)
@@ -684,6 +689,7 @@ end
684689
# Print a stack frame where the module color is set manually with `modulecolor`.
685690
function print_stackframe(io, i, frame::StackFrame, n::Int, digit_align_width, modulecolor)
686691
file, line = string(frame.file), frame.line
692+
file = fixup_stdlib_path(file)
687693
stacktrace_expand_basepaths() && (file = something(find_source_file(file), file))
688694
stacktrace_contract_userdir() && (file = contractuser(file))
689695

stdlib/InteractiveUtils/test/runtests.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,31 @@ file, ln = functionloc(versioninfo, Tuple{})
563563
@test isfile(pathof(InteractiveUtils))
564564
@test isdir(pkgdir(InteractiveUtils))
565565

566+
@testset "buildbot path updating" begin
567+
file, ln = functionloc(versioninfo, Tuple{})
568+
@test isfile(file)
569+
570+
e = try versioninfo("wat")
571+
catch e
572+
e
573+
end
574+
@test e isa MethodError
575+
m = @which versioninfo()
576+
s = sprint(showerror, e)
577+
m = match(Regex("at (.*?):$(m.line)"), s)
578+
@test isfile(expanduser(m.captures[1]))
579+
580+
g() = x
581+
e, bt = try code_llvm(g, Tuple{Int})
582+
catch e
583+
e, catch_backtrace()
584+
end
585+
@test e isa Exception
586+
s = sprint(showerror, e, bt)
587+
m = match(r"(\S*InteractiveUtils[\/\\]src\S*):", s)
588+
@test isfile(expanduser(m.captures[1]))
589+
end
590+
566591
@testset "Issue #34434" begin
567592
io = IOBuffer()
568593
code_native(io, eltype, Tuple{Int})

test/errorshow.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ include("testenv.jl")
4848
end
4949
end
5050

51-
52-
cfile = " at $(@__FILE__):"
51+
file = @__FILE__
52+
Base.stacktrace_contract_userdir() && (file = Base.contractuser(file))
53+
cfile = " at $file:"
5354
c1line = @__LINE__() + 1
5455
method_c1(x::Float64, s::AbstractString...) = true
5556

test/worlds.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ f265(::Int) = 1
136136

137137
# test for method errors
138138
h265() = true
139-
loc_h265 = "$(@__FILE__):$(@__LINE__() - 1)"
139+
file = @__FILE__
140+
Base.stacktrace_contract_userdir() && (file = Base.contractuser(file))
141+
loc_h265 = "$file:$(@__LINE__() - 3)"
140142
@test h265()
141143
@test_throws TaskFailedException(t265) put_n_take!(h265, ())
142144
@test_throws TaskFailedException(t265) fetch(t265)

0 commit comments

Comments
 (0)