Skip to content

fix some issues with buildbot path not updating in stacktraces / method errors #37427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))

Expand Down
25 changes: 25 additions & 0 deletions stdlib/InteractiveUtils/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,31 @@ 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
m = @which versioninfo()
s = sprint(showerror, e)
m = match(Regex("at (.*?):$(m.line)"), s)
@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})
Expand Down
5 changes: 3 additions & 2 deletions test/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion test/worlds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down