better-panic
better-panic copied to clipboard
Use `better-panic` to format externally provided backtraces.
Hi,
I love the output formatting that better panic provides :) My application captures backtraces in some flows to print them to the user, but it then resumes operation, so it doesn't "panic" in the normal sense a panic would occur.
I'd like to apply the same formatting style better-panic
uses when printing the backtraces, but Settings
only provides a public API to install a panic hook.
Would it be possible to expose some API that you would consider stable for backtraces formatting, something like:
let settings = Settings::auto();
let formatted_backtrace = settings.format_bt(&bt);
Thanks!
@omerbenamram While this wouldn't give you control on where you actually print the panic message, if you use the existing install()
function to setup better_panic
, better_panic
will still print the backtrace to the console, even if you capture the panic with a std::panic::catch_unwind
.
That is how I'm doing it in my CLI app. I capture any panics that occur during execution, better_panic
will print out the pretty panic message, and then I print a message like:
Error: The program has encountered a critical internal error and will now exit. This is a bug. Please report it on our issue tracker:
This might not work for you still if you need to print the panic message yourself.