Skip to content
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

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

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

mortenpi
Copy link
Contributor

@mortenpi mortenpi commented Dec 3, 2023

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.

bt = get_backtrace(ex)
@info("Unexpected error: $bt")
@info "Unexpected error" exception = (ex, catch_backtrace())
bt = sprint(Base.showerror, ex, catch_backtrace())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a tiny bit of duplication in two places. But I feel that if raise_issue should be doing some special printing, then there should probably be a special method for that function.

@nkottary nkottary merged commit 840fd69 into JuliaRegistries:master Jan 30, 2024
6 of 7 checks passed
@mortenpi mortenpi deleted the mp/remote-get-backtrace branch January 30, 2024 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants