MCPcopy Create free account
hub / github.com/0xMiden/node / catch_panic_layer_fn

Function catch_panic_layer_fn

crates/utils/src/panic.rs:14–29  ·  view source on GitHub ↗
(err: Box<dyn Any + Send + 'static>)

Source from the content-addressed store, hash-verified

12/// This should be added to tonic server builder as a layer via [`CatchPanicLayer::custom()`].
13#[track_caller]
14pub 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.
32fn stringify_panic_error(err: Box<dyn Any + Send + 'static>) -> String {

Callers

nothing calls this directly

Calls 5

stringify_panic_errorFunction · 0.85
set_errorMethod · 0.80
headerMethod · 0.80
statusMethod · 0.80
as_refMethod · 0.45

Tested by

no test coverage detected