Add try/catch around handle_message() to catch errors during logging. (#57004)
Fixes https://github.com/JuliaLang/julia/issues/56889.
Before this PR, an exception thrown while constructing the objects to
log (the `msg`) would be caught and logged. However, an exception thrown
while _printing_ the msg to an IO would _not_ be caught, and can abort
the program. This breaks the promise that enabling verbose debug logging
shouldn't introduce new crashes.
After this PR, an exception thrown during handle_message is caught and
logged, just like an exception during `msg` construction:
```julia
julia> struct Foo end
julia> Base.show(::IO, ::Foo) = error("oh no")
julia> begin
# Unexpectedly, the execption thrown while printing `Foo()` escapes
@info Foo()
# So we never reach this line! :'(
println("~~~~~ ALL DONE ~~~~~~~~")
end
┌ Error: Exception while generating log record in module Main at REPL[10]:3
│ exception =
│ oh no
│ Stacktrace:
│ [1] error(s::String)
│ @ Base ./error.jl:44
│ [2] show(::IOBuffer, ::Foo)
│ @ Main ./REPL[9]:1
...
│ [30] repl_main
│ @ ./client.jl:593 [inlined]
│ [31] _start()
│ @ Base ./client.jl:568
└ @ Main REPL[10]:3
~~~~~ ALL DONE ~~~~~~~~
```
This PR respects the change made in
https://github.com/JuliaLang/julia/pull/36600 to keep the codegen as
small as possible, by putting the new try/catch into a no-inlined
function, so that we don't have to introduce a new try/catch in the
macro-generated code body.
---------
Co-authored-by: Jameson Nash <vtjnash@gmail.com>