Skip to content

Commit

Permalink
Merge pull request #25569 from JuliaLang/cjf/logging-backtraces
Browse files Browse the repository at this point in the history
Attach backtraces explicitly in error logging
  • Loading branch information
c42f authored Jan 17, 2018
2 parents 2042dcf + faf1d7c commit d548bf9
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 16 deletions.
7 changes: 2 additions & 5 deletions base/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,8 @@ There's also some key value pairs which have conventional meaning:
* `maxlog=integer` should be used as a hint to the backend that the message
should be displayed no more than `maxlog` times.
* `exception=ex` should be used to transport an exception with a log message,
often used with `@error`. `AbstractLoggers` should assume that the
associated backtrace can be obtained from `catch_backtrace()`. If the log
message is emitted outside the catch block which generated `ex`, an
associated backtrace `bt` may be attached explicitly using
`exception=(ex,bt)`.
often used with `@error`. An associated backtrace `bt` may be attached
using the tuple `exception=(ex,bt)`.
# Examples
Expand Down
6 changes: 3 additions & 3 deletions base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ function build(pkg::AbstractString, build_file::AbstractString, errfile::Abstrac
@error \"""
------------------------------------------------------------
# Build failed for \$pkg
\""" exception=err
\""" exception=err,catch_backtrace()
serialize(f, pkg)
serialize(f, err)
end
Expand Down Expand Up @@ -673,7 +673,7 @@ function updatehook!(pkgs::Vector, errs::Dict, seen::Set=Set())
@error """
------------------------------------------------------------
# Update hook failed for $pkg
""" exception=err
""" exception=err,catch_backtrace()
errs[pkg] = err
end
end
Expand Down Expand Up @@ -733,7 +733,7 @@ function test!(pkg::AbstractString,
@error """
------------------------------------------------------------
# Testing failed for $pkg
""" exception=err
""" exception=err,catch_backtrace()
push!(errs,pkg)
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/repl/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2317,7 +2317,7 @@ function prompt!(term::TextTerminal, prompt::ModalInterface, s::MIState = init_s
try
status = fcn(s, kdata)
catch e
@error "Error in the keymap" exception=e
@error "Error in the keymap" exception=e,catch_backtrace()
# try to cleanup and get `s` back to its original state before returning
transition(s, :reset)
transition(s, old_state)
Expand Down
2 changes: 1 addition & 1 deletion base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ function showerror(io::IO, ex::MethodError)
try
show_method_candidates(io, ex, kwargs)
catch ex
@error "Error showing method candidates, aborted" exception=ex
@error "Error showing method candidates, aborted" exception=ex,catch_backtrace()
end
end

Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ function terminate_all_workers()
try
rmprocs(workers(); waitfor=5.0)
catch _ex2
@error "Unable to terminate all workers" exception=_ex2
@error "Unable to terminate all workers" exception=_ex2,catch_backtrace()
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions stdlib/Distributed/src/process_messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function deliver_result(sock::IO, msg, oid, value)
catch e
# terminate connection in case of serialization error
# otherwise the reading end would hang
@error "Fatal error on process $(myid())" exception=e
@error "Fatal error on process $(myid())" exception=e,catch_backtrace()
wid = worker_id_from_socket(sock)
close(sock)
if myid()==1
Expand Down Expand Up @@ -210,7 +210,7 @@ function message_handler_loop(r_stream::IO, w_stream::IO, incoming::Bool)
# If unhandleable error occurred talking to pid 1, exit
if wpid == 1
if isopen(w_stream)
@error "Fatal error on process $(myid())" exception=e
@error "Fatal error on process $(myid())" exception=e,catch_backtrace()
end
exit(1)
end
Expand Down Expand Up @@ -341,7 +341,7 @@ function connect_to_peer(manager::ClusterManager, rpid::Int, wconfig::WorkerConf
send_connection_hdr(w, true)
send_msg_now(w, MsgHeader(), IdentifySocketMsg(myid()))
catch e
@error "Error on $(myid()) while connecting to peer $rpid, exiting" exception=e
@error "Error on $(myid()) while connecting to peer $rpid, exiting" exception=e,catch_backtrace()
exit(1)
end
end
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Logging/src/ConsoleLogger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function showvalue(io, e::Tuple{Exception,Any})
ex,bt = e
showerror(io, ex, bt; backtrace = bt!=nothing)
end
showvalue(io, ex::Exception) = showvalue(io, (ex,catch_backtrace()))
showvalue(io, ex::Exception) = showerror(io, ex)

function default_logcolor(level)
level < Info ? Base.debug_color() :
Expand Down
2 changes: 1 addition & 1 deletion stdlib/SuiteSparse/src/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function __init__()
end

catch ex
@error "Error during initialization of module CHOLMOD" exception=ex
@error "Error during initialization of module CHOLMOD" exception=ex,catch_backtrace()
end
end

Expand Down

0 comments on commit d548bf9

Please sign in to comment.