rwf2 / Rocket

A web framework for Rust.

Home Page:https://rocket.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Supply PanicInfo to Catchers where applicable

phayes opened this issue · comments

What's missing?

Most large complex applications have panics despite our best efforts to the contrary. Good visibility into these panics is the first step to fixing them. In terms of panics, good visibility means logging both the request that caused the panic along with the details of the panic. This is currently not possible in Rocket, as the Catcher functionality does not provide PanicInfo.

Ideal Solution

Ideally, A function decorated with #[catch] may take an additional argument: Option<PanicInfo> that will be either Some<PanicInfo> when the catcher is being caused because of a panic, or None when this is not the case.

The user will then be able to log both the panic, and details about the request that caused the panic, leading to greater visibility into the root cause of the panic and allowing the panic to be eliminated.

Why can't this be implemented outside of Rocket?

Good visibility into panics requires logging both request-information and panic information together. This isn't currently possible without support from Rocket.

Are there workarounds usable today?

The current workaround is to log the panic information (using std::panic::set_hook) and the request information (using #[catch]) separately. This isn't ideal because on a busy server these log messages might be quite far apart and hard to link which panic corresponds to which request.

Alternative Solutions

No response

Additional Context

There is a stack-overflow related to this here: https://stackoverflow.com/questions/76911134/is-it-possible-to-get-the-rust-rocket-500-error-message

System Checks

  • I do not believe that this feature can or should be implemented outside of Rocket.
  • I was unable to find a previous request for this feature.

Just realized that Rocket may not have a full PanicInfo but merely a Box<dyn Any + Send>> (from a std::panic::catch_unwind). Even a Box<dyn Any + Send>> that could be downcasted would be very useful.

This is #749, which covers this case and many others.