task_panic_data

Attribute Macro task_panic_data 

Source
#[task_panic_data]
Expand description

Extracts panic data into a variable with panic on missing value.

This attribute macro retrieves panic information if a panic occurred during handling and makes it available as a variable. If no panic data exists, the function will panic with an error message.

§Usage

use hyperlane::*;
use hyperlane_macros::*;

#[route("/task_panic_data")]
struct PanicDataTest;

impl ServerHook for PanicDataTest {
    async fn new(_ctx: &Context) -> Self {
        Self
    }

    #[response_body(&format!("Panic data: {task_panic_data}"))]
    #[task_panic_data(task_panic_data)]
    async fn handle(self, ctx: &Context) {}
}

impl PanicDataTest {
    #[task_panic_data(task_panic_data)]
    async fn task_panic_data_with_ref_self(&self, ctx: &Context) {}
}

#[task_panic_data(task_panic_data)]
async fn standalone_task_panic_data_handler(ctx: &Context) {}

The macro accepts a variable name that will contain the panic data. The variable will be available as a PanicData in the function scope.

§Multi-Parameter Usage

use hyperlane::*;
use hyperlane_macros::*;

#[route("/task_panic_data")]
struct MultiPanicData;

impl ServerHook for MultiPanicData {
    async fn new(_ctx: &Context) -> Self {
        Self
    }

    #[response_body(&format!("panic1: {panic1}, panic2: {panic2}"))]
    #[task_panic_data(panic1, panic2)]
    async fn handle(self, ctx: &Context) {}
}

The macro accepts multiple variable names separated by commas.

§Panics

This macro will panic if no panic data exists in the request context.