JuliaRegistries / Registrator.jl

Julia package registration bot
https://julialang.org/packages
Other
210 stars 47 forks source link

Don't use the `exception=get_backtrace(...)` pattern #428

Closed mortenpi closed 7 months ago

mortenpi commented 9 months ago

It makes the stacktraces from the error handlers pretty much useless and hinders debugging. In particular, since exception is now just a string, the logging macros will elide most of the stacktrace. As an MWE:

julia> try
       error("1234")
       catch e
       @error "Error handler" exception = sprint(Base.showerror, e, catch_backtrace())
       end
┌ Error: Error handler
│   exception = "1234\nStacktrace:\n  [1] error(s::String)\n    @ Base ./error.jl:35\n  [2] top-level scope\n    @ REPL[9]:2\n  [3] eval\n    @ ./boot.jl:370 [inlined]\n  [4] eval_user_input(ast::Any, backend::REPL.REPLBackend, mod::Module)\n    @ REPL ~/.julia/juliaup/julia-1.9" ⋯ 974 bytes ⋯ "816 [inlined]\n [12] run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool)\n    @ Base ./client.jl:405\n [13] exec_options(opts::Base.JLOptions)\n    @ Base ./client.jl:322\n [14] _start()\n    @ Base ./client.jl:522"
└ @ Main REPL[9]:4

Instead I suggest using the standard exception = (e, catch_backtrace()) pattern.