Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
  • Loading branch information
NHDaly and vtjnash authored Jan 15, 2025
1 parent 80f8e10 commit e9374b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
7 changes: 4 additions & 3 deletions base/logging/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,13 @@ function logmsg_code(_module, file, line, level, message, exs...)
end
end

@noinline function handle_message_nothrow(logger, level, msg, _module, group, id, file,
line, args...; kwargs...)
@noinline function handle_message_nothrow(logger, level, msg, _module, group, id, file, line; kwargs...)
@nospecialize
try
@invokelatest handle_message(
logger, level, msg, _module, group, id, file, line, args...;
logger, level, msg, _module, group, id, file, line;
kwargs...)

catch err
@invokelatest logging_error(logger, level, _module, group, id, file, line, err, true)
end
Expand Down
19 changes: 2 additions & 17 deletions test/corelogging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,11 @@ end
end
end
@testset "Log message handle_message exception handling" begin
function capture_stderr(func)
fname = tempname()
f = open(fname, "w")
redirect_stderr(f) do
func()
end
close(f)
buf = read(fname)
rm(fname)
String(buf)
end

# Exceptions in log handling (printing) of msg are caught by default
struct Foo end
Base.show(::IO, ::Foo) = 1 ÷ 0
out = capture_stderr() do
@info Foo()
end
@test occursin("Error: Exception while generating log record in module Main at", out)
@test occursin("DivideError: integer division error", out)

@test_warn r"Error: Exception while generating log record in module Main at.*DivideError: integer division error" @info Foo()

# Exceptions in log handling (printing) of attributes are caught by default
out = capture_stderr() do
Expand Down

0 comments on commit e9374b1

Please sign in to comment.