From 493a17ad8a6f4b159d290b992752843dae98cec5 Mon Sep 17 00:00:00 2001 From: Kristoffer Date: Sun, 6 Sep 2020 12:10:25 +0200 Subject: [PATCH 1/3] fix some issues with buildbot path not updating in stacktraces / method errors --- base/errorshow.jl | 22 +++++++++++------ stdlib/InteractiveUtils/test/runtests.jl | 31 ++++++++++++++++++++++++ test/errorshow.jl | 5 ++-- test/worlds.jl | 4 ++- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/base/errorshow.jl b/base/errorshow.jl index 3387141adfe40..121fb50db91c1 100644 --- a/base/errorshow.jl +++ b/base/errorshow.jl @@ -367,6 +367,13 @@ function showerror_nostdio(err, msg::AbstractString) ccall(:jl_printf, Cint, (Ptr{Cvoid},Cstring), stderr_stream, "\n") end +stacktrace_expand_basepaths()::Bool = + tryparse(Bool, get(ENV, "JULIA_STACKTRACE_EXPAND_BASEPATHS", "false")) === true +stacktrace_contract_userdir()::Bool = + tryparse(Bool, get(ENV, "JULIA_STACKTRACE_CONTRACT_HOMEDIR", "true")) === true +stacktrace_linebreaks()::Bool = + tryparse(Bool, get(ENV, "JULIA_STACKTRACE_LINEBREAKS", "false")) === true + function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()) is_arg_types = isa(ex.args, DataType) arg_types = is_arg_types ? ex.args : typesof(ex.args...) @@ -494,7 +501,12 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=() end print(iob, ")") show_method_params(iob0, tv) - print(iob, " at ", method.file, ":", method.line) + file, line = functionloc(method) + if file === nothing + file = string(method.file) + end + stacktrace_contract_userdir() && (file = contractuser(file)) + print(iob, " at ", file, ":", line) if !isempty(kwargs)::Bool unexpected = Symbol[] if isempty(kwords) || !(any(endswith(string(kword), "...") for kword in kwords)) @@ -554,13 +566,6 @@ const update_stackframes_callback = Ref{Function}(identity) const STACKTRACE_MODULECOLORS = [:magenta, :cyan, :green, :yellow] const STACKTRACE_FIXEDCOLORS = IdDict(Base => :light_black, Core => :light_black) -stacktrace_expand_basepaths()::Bool = - tryparse(Bool, get(ENV, "JULIA_STACKTRACE_EXPAND_BASEPATHS", "false")) === true -stacktrace_contract_userdir()::Bool = - tryparse(Bool, get(ENV, "JULIA_STACKTRACE_CONTRACT_HOMEDIR", "true")) === true -stacktrace_linebreaks()::Bool = - tryparse(Bool, get(ENV, "JULIA_STACKTRACE_LINEBREAKS", "false")) === true - function show_full_backtrace(io::IO, trace::Vector; print_linebreaks::Bool) num_frames = length(trace) ndigits_max = ndigits(num_frames) @@ -689,6 +694,7 @@ end # Print a stack frame where the module color is set manually with `modulecolor`. function print_stackframe(io, i, frame::StackFrame, n::Int, digit_align_width, modulecolor) file, line = string(frame.file), frame.line + file = fixup_stdlib_path(file) stacktrace_expand_basepaths() && (file = something(find_source_file(file), file)) stacktrace_contract_userdir() && (file = contractuser(file)) diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index 43f65c9bcb6cc..23501e45bedb6 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -568,6 +568,37 @@ file, ln = functionloc(versioninfo, Tuple{}) @test isfile(pathof(InteractiveUtils)) @test isdir(pkgdir(InteractiveUtils)) +@testset "buildbot path updating" begin + file, ln = functionloc(versioninfo, Tuple{}) + @test isfile(file) + + e = try versioninfo("wat") + catch e + e + end + @test e isa MethodError + s = sprint(showerror, e) + m = match(r"at (.*?):[0-9]*", s) + @info "DEBUG START" + println(s) + println(m) + println(m.captures[1]) + println(expandusers(m.captures[1])) + @info "DEBUG END" + + @test isfile(expanduser(m.captures[1])) + + g() = x + e, bt = try code_llvm(g, Tuple{Int}) + catch e + e, catch_backtrace() + end + @test e isa Exception + s = sprint(showerror, e, bt) + m = match(r"(\S*InteractiveUtils[\/\\]src\S*):", s) + @test isfile(expanduser(m.captures[1])) +end + @testset "Issue #34434" begin io = IOBuffer() code_native(io, eltype, Tuple{Int}) diff --git a/test/errorshow.jl b/test/errorshow.jl index 676cc3bc8ccd9..32b7c417a5909 100644 --- a/test/errorshow.jl +++ b/test/errorshow.jl @@ -48,8 +48,9 @@ include("testenv.jl") end end - -cfile = " at $(@__FILE__):" +file = @__FILE__ +Base.stacktrace_contract_userdir() && (file = Base.contractuser(file)) +cfile = " at $file:" c1line = @__LINE__() + 1 method_c1(x::Float64, s::AbstractString...) = true diff --git a/test/worlds.jl b/test/worlds.jl index c8d671bea63d8..8a0c936d3df8d 100644 --- a/test/worlds.jl +++ b/test/worlds.jl @@ -152,7 +152,9 @@ f265(::Int) = 1 # test for method errors h265() = true -loc_h265 = "$(@__FILE__):$(@__LINE__() - 1)" +file = @__FILE__ +Base.stacktrace_contract_userdir() && (file = Base.contractuser(file)) +loc_h265 = "$file:$(@__LINE__() - 3)" @test h265() @test_throws TaskFailedException(t265) put_n_take!(h265, ()) @test_throws TaskFailedException(t265) fetch(t265) From 4381cab69e489a94158467740d8353b15febc72f Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Sun, 10 Oct 2021 17:53:13 -0400 Subject: [PATCH 2/3] Update debug stdlib/InteractiveUtils/test/runtests.jl --- stdlib/InteractiveUtils/test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index 23501e45bedb6..51d619e6cf4d8 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -583,7 +583,7 @@ file, ln = functionloc(versioninfo, Tuple{}) println(s) println(m) println(m.captures[1]) - println(expandusers(m.captures[1])) + println(expanduser(m.captures[1])) @info "DEBUG END" @test isfile(expanduser(m.captures[1])) From b63d2545667df45591eaa24a011910cc8c4ee05d Mon Sep 17 00:00:00 2001 From: Kristoffer Date: Sun, 6 Sep 2020 12:10:25 +0200 Subject: [PATCH 3/3] fix some issues with buildbot path not updating in stacktraces / method errors --- stdlib/InteractiveUtils/test/runtests.jl | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index 51d619e6cf4d8..ccf57e157e31f 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -577,15 +577,9 @@ file, ln = functionloc(versioninfo, Tuple{}) e end @test e isa MethodError + m = @which versioninfo() s = sprint(showerror, e) - m = match(r"at (.*?):[0-9]*", s) - @info "DEBUG START" - println(s) - println(m) - println(m.captures[1]) - println(expanduser(m.captures[1])) - @info "DEBUG END" - + m = match(Regex("at (.*?):$(m.line)"), s) @test isfile(expanduser(m.captures[1])) g() = x