Skip to content

Commit f9b5108

Browse files
KristofferCvchuravy
authored andcommitted
fix some issues with buildbot path not updating in stacktraces / method errors
1 parent a512f1a commit f9b5108

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed

base/errorshow.jl

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

370+
stacktrace_expand_basepaths()::Bool =
371+
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_EXPAND_BASEPATHS", "false")) === true
372+
stacktrace_contract_userdir()::Bool =
373+
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_CONTRACT_HOMEDIR", "true")) === true
374+
stacktrace_linebreaks()::Bool =
375+
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_LINEBREAKS", "false")) === true
376+
370377
function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=())
371378
is_arg_types = isa(ex.args, DataType)
372379
arg_types = is_arg_types ? ex.args : typesof(ex.args...)
@@ -494,7 +501,12 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
494501
end
495502
print(iob, ")")
496503
show_method_params(iob0, tv)
497-
print(iob, " at ", method.file, ":", method.line)
504+
file, line = functionloc(method)
505+
if file === nothing
506+
file = string(method.file)
507+
end
508+
stacktrace_contract_userdir() && (file = contractuser(file))
509+
print(iob, " at ", file, ":", line)
498510
if !isempty(kwargs)::Bool
499511
unexpected = Symbol[]
500512
if isempty(kwords) || !(any(endswith(string(kword), "...") for kword in kwords))
@@ -554,13 +566,6 @@ const update_stackframes_callback = Ref{Function}(identity)
554566
const STACKTRACE_MODULECOLORS = [:magenta, :cyan, :green, :yellow]
555567
const STACKTRACE_FIXEDCOLORS = IdDict(Base => :light_black, Core => :light_black)
556568

557-
stacktrace_expand_basepaths()::Bool =
558-
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_EXPAND_BASEPATHS", "false")) === true
559-
stacktrace_contract_userdir()::Bool =
560-
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_CONTRACT_HOMEDIR", "true")) === true
561-
stacktrace_linebreaks()::Bool =
562-
tryparse(Bool, get(ENV, "JULIA_STACKTRACE_LINEBREAKS", "false")) === true
563-
564569
function show_full_backtrace(io::IO, trace::Vector; print_linebreaks::Bool)
565570
num_frames = length(trace)
566571
ndigits_max = ndigits(num_frames)
@@ -689,6 +694,7 @@ end
689694
# Print a stack frame where the module color is set manually with `modulecolor`.
690695
function print_stackframe(io, i, frame::StackFrame, n::Int, digit_align_width, modulecolor)
691696
file, line = string(frame.file), frame.line
697+
file = fixup_stdlib_path(file)
692698
stacktrace_expand_basepaths() && (file = something(find_source_file(file), file))
693699
stacktrace_contract_userdir() && (file = contractuser(file))
694700

stdlib/InteractiveUtils/test/runtests.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,37 @@ file, ln = functionloc(versioninfo, Tuple{})
568568
@test isfile(pathof(InteractiveUtils))
569569
@test isdir(pkgdir(InteractiveUtils))
570570

571+
@testset "buildbot path updating" begin
572+
file, ln = functionloc(versioninfo, Tuple{})
573+
@test isfile(file)
574+
575+
e = try versioninfo("wat")
576+
catch e
577+
e
578+
end
579+
@test e isa MethodError
580+
s = sprint(showerror, e)
581+
m = match(r"at (.*?):[0-9]*", s)
582+
@info "DEBUG START"
583+
println(s)
584+
println(m)
585+
println(m.captures[1])
586+
println(expandusers(m.captures[1]))
587+
@info "DEBUG END"
588+
589+
@test isfile(expanduser(m.captures[1]))
590+
591+
g() = x
592+
e, bt = try code_llvm(g, Tuple{Int})
593+
catch e
594+
e, catch_backtrace()
595+
end
596+
@test e isa Exception
597+
s = sprint(showerror, e, bt)
598+
m = match(r"(\S*InteractiveUtils[\/\\]src\S*):", s)
599+
@test isfile(expanduser(m.captures[1]))
600+
end
601+
571602
@testset "Issue #34434" begin
572603
io = IOBuffer()
573604
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
@@ -152,7 +152,9 @@ f265(::Int) = 1
152152

153153
# test for method errors
154154
h265() = true
155-
loc_h265 = "$(@__FILE__):$(@__LINE__() - 1)"
155+
file = @__FILE__
156+
Base.stacktrace_contract_userdir() && (file = Base.contractuser(file))
157+
loc_h265 = "$file:$(@__LINE__() - 3)"
156158
@test h265()
157159
@test_throws TaskFailedException(t265) put_n_take!(h265, ())
158160
@test_throws TaskFailedException(t265) fetch(t265)

0 commit comments

Comments
 (0)