pub fn trap(msg: String) -> ! {
#[cfg(target_family = "wasm")]
{
ic_cdk::trap(msg);
}
#[cfg(not(target_family = "wasm"))]
{
std::panic::panic_any(msg)
}
}
#[macro_export]
macro_rules! trap {
($($key:tt $(:$capture:tt)? $(= $value:expr)?),+; $($arg:tt)+) => ({
$crate::utils::trap(format!($($arg)+));
});
( $($arg:tt)+) => ({
$crate::utils::trap(format!($($arg)+));
});
}
#[cfg(test)]
mod tests {
#[test]
#[should_panic(expected = "This is a test trap message with value: 100")]
fn test_trap_macro() {
crate::trap!("This is a test trap message with value: {}", 100);
}
}