Skip to content

Pretty print panic information #837

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

Closed
andreeaflorescu opened this issue Jan 10, 2019 · 2 comments
Closed

Pretty print panic information #837

andreeaflorescu opened this issue Jan 10, 2019 · 2 comments

Comments

@andreeaflorescu
Copy link
Member

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.
@andreeaflorescu
Copy link
Member Author

Looking at the human_panic code it doesn't seem like it does what we need it to do :(

@andreeaflorescu
Copy link
Member Author

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).

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

No branches or pull requests

1 participant