(err: Box<dyn Any + Send + 'static>)
| 12 | /// This should be added to tonic server builder as a layer via [`CatchPanicLayer::custom()`]. |
| 13 | #[track_caller] |
| 14 | pub fn catch_panic_layer_fn(err: Box<dyn Any + Send + 'static>) -> Response<Full<bytes::Bytes>> { |
| 15 | // Log the panic error details. |
| 16 | let err = stringify_panic_error(err); |
| 17 | tracing::error!(panic = true, error = %err, "panic"); |
| 18 | |
| 19 | // Mark the current span as failed for OpenTelemetry. |
| 20 | let wrapped = anyhow::Error::msg(err.clone()); |
| 21 | tracing::Span::current().set_error(wrapped.as_ref()); |
| 22 | |
| 23 | // Return generic error response. |
| 24 | Response::builder() |
| 25 | .status(StatusCode::INTERNAL_SERVER_ERROR) |
| 26 | .header(header::CONTENT_TYPE, "application/grpc") |
| 27 | .body(Full::from("")) |
| 28 | .unwrap() |
| 29 | } |
| 30 | |
| 31 | /// Converts a dynamic panic-related error into a string. |
| 32 | fn stringify_panic_error(err: Box<dyn Any + Send + 'static>) -> String { |
nothing calls this directly
no test coverage detected