Is it possible to suppress printing of a panic message (“thread panicked at”)?
I have a parent superviser thread which launches a child thread.
The child can sometimes panic, but is safe to just restart.
So I don’t want to see the default panic message in the stderr and instead I want to provide my own reporting. I know that at least on nightly I can provide my own panic handler (and mess something up along the way ), but it seems like a too complex solution for my use case.
+1 for ability to customise a panic message.
In expectest I’m using panicking::panic_fmt (here). It’s all good but without “thread panicked at” it would be better.
I also think that std::panic::set_hook is overkill for me.
I understood the philosophy that panics in rust are never on purpose and exception handling is not mature enough in rust and not always possible. Result with either item value or an error is the way to handle errors, the rest (panic and assertions) are not bona fine errors. Am I missing something?
The crate is basically a test harness helper, used to test how code behaves under a panic.
Indeed, it should not be used in any production-destined software (but see below). That said, in Rust, catching a panic on a thread boundary is a valid failure isolation mechanism. There is also catch_unwind, which definitely should not be used for this purpose; its only legitimate use is to prevent unwinding into non-Rust code.
By “bona fide errors” I meant fatal conditions that cause “real” panics. These need to be distinguished from the simulated panic under test, in that a thread that calls join() on the panicked thread’s handle should still get an Err if the panic is not of the expected type.
I think this is a bit too strong of a statement. catch_unwind can be used to create “less-than-a-thread” isolation boundaries within application itself. For example, one might want to isolate independent async tasks.