Pretty print panic information
andreeaflorescu opened this issue · 2 comments
We have a panic hook in Firecracker that is logging the panic info as is:
panic::set_hook(Box::new(move |info| {
error!("Panic occurred: {:?}", info);
....This results in ugly printed messages, that cause confusion about the error that generated the panic.
For example, when the API socket is already in used, we would get an error message as follows:
2019-01-10T16:23:27.009840936 [anonymous-instance:ERROR:src/main.rs:50] Panic occurred: PanicInfo { payload: Any, message: Some(Failed to open the API socket: IO Error: Io(Os { code: 98, kind: AddrInUse, message: "Address in use" })), location: Location { file: "src/main.rs", line: 137, col: 37 } }We should use the information from the panic info (PanicInfo structure) and log a human readable error.
The problem is that right now the panic info message (which contains the error that generated the panic) is only available in rust nightly builds.
I am not sure when/if the message function will be in rust-stable and it might be worth investigating if we can use the human_panic crate.
Example of a pretty-print:
Panic occurred. Error message: API Socket already in use.
The Panic occurred in the "src/main.rs" file at line 137, column 37.
Looking at the human_panic code it doesn't seem like it does what we need it to do :(
PanicInfo implements Display, so we end up with something like:
Panic occurred: panicked at 'Failed to open the API socket: IO Error: Io(Os { code: 98, kind: AddrInUse, message: "Address in use" })', src/main.rs:137:37
instead of:
Panic occurred: PanicInfo { payload: Any, message: Some(Failed to open the API socket: IO Error: Io(Os { code: 98, kind: AddrInUse, message: "Address in use" })), location: Location { file: "src/main.rs", line: 137, col: 37 } }
which is already a nice improvement.
To have the inner error message pretty printed we have to also implement Display for those errors (e.g. AddrInUse and Error from vmm/src/lib.rs).