task_panic_data_option

Attribute Macro task_panic_data_option 

Source
#[task_panic_data_option]
Expand description

Extracts panic data into a variable wrapped in Option type.

This attribute macro retrieves panic information if a panic occurred during handling and makes it available as an Option variable. The extracted value is wrapped in an Option type to safely handle cases where no panic occurred.

§Usage

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

#[route("/task_panic_data_option")]
struct PanicDataOptionTest;

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

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

impl PanicDataOptionTest {
    #[task_panic_data_option(task_panic_data_option)]
    async fn task_panic_data_option_with_ref_self(&self, ctx: &Context) {}
}

#[task_panic_data_option(task_panic_data_option)]
async fn standalone_task_panic_data_option_handler(ctx: &Context) {}

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

§Multi-Parameter Usage

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

#[route("/task_panic_data_option")]
struct MultiPanicDataOption;

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

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

The macro accepts multiple variable names separated by commas.