{"record":{"id":"321911b5edfcc7e7","repo":"embassy-rs/embassy","slug":"unwrap-of-failed-321911","errorCode":null,"errorMessage":"unwrap of `{}` failed: {}: {:?}","messagePattern":"unwrap of `(.+?)` failed: (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-nrf/src/fmt.rs","lineNumber":210,"sourceCode":"    };\n}\n\n#[cfg(not(feature = \"defmt\"))]\n#[collapse_debuginfo(yes)]\nmacro_rules! unwrap {\n    ($arg:expr) => {\n        match $crate::fmt::Try::into_result($arg) {\n            ::core::result::Result::Ok(t) => t,\n            ::core::result::Result::Err(e) => {\n                ::core::panic!(\"unwrap of `{}` failed: {:?}\", ::core::stringify!($arg), e);\n            }\n        }\n    };\n    ($arg:expr, $($msg:expr),+ $(,)? ) => {\n        match $crate::fmt::Try::into_result($arg) {\n            ::core::result::Result::Ok(t) => t,\n            ::core::result::Result::Err(e) => {\n                ::core::panic!(\"unwrap of `{}` failed: {}: {:?}\", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e);\n            }\n        }\n    }\n}\n\n#[derive(Debug, Copy, Clone, Eq, PartialEq)]\npub struct NoneError;\n\npub trait Try {\n    type Ok;\n    type Error;\n    fn into_result(self) -> Result<Self::Ok, Self::Error>;\n}\n\nimpl<T> Try for Option<T> {\n    type Ok = T;\n    type Error = NoneError;\n","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-nrf/src/fmt.rs#L192-L228","documentation":"Variant of embassy's `unwrap!` macro that accepts extra message arguments: `unwrap!(expr, \"context {}\", x)`. When the expression yields Err (or None), it panics with the expression text, the user-supplied context, and the Debug-formatted error. As with the plain form, the root cause is the inner Err value surfaced by `Try::into_result`.","triggerScenarios":"Any call site using `unwrap!(expr, msg...)` where expr returns Err/None — the extra arguments are diagnostic context only; the failure is produced by the same underlying driver/peripheral errors as the one-argument form (e.g. failed peripheral init, DMA setup, or channel send).","commonSituations":"Same as the plain unwrap: invalid peripheral setup, wrong buffer sizes or alignment, dropped sender on an ipc/channel, invalid enum values for the chip variant — with the extra context identifying the subsystem that failed.","solutions":["Read both the expression text and the extra context message in the panic output to locate the failing subsystem","Inspect the Debug-formatted error value for the concrete cause","Replace the macro call with explicit error handling (match/? ) for that call site","Validate the arguments passed at that call site (pins, buffers, enums) against the driver's documented requirements"],"exampleFix":"// before\nlet res = unwrap!(init_peripheral(cfg), \"init failed for {}\", name);\n// after\nlet res = match init_peripheral(cfg) {\n    Ok(r) => r,\n    Err(e) => {\n        defmt::error!(\"init failed for {}: {:?}\", name, e);\n        return Err(e);\n    }\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Replace unwrap!(expr, ctx...) with explicit handling:\n// match op() {\n//     Ok(v) => v,\n//     Err(e) => { defmt::error!(\"{}: {:?}\", ctx, e); return Err(e); }\n// }","preventionTips":["Use the macro's context message in the panic to narrow the failing subsystem","Prefer explicit error propagation over unwrap! in production firmware","Assert argument validity (buffer sizes, pin mappings, enum values) before fallible calls","Test fallible paths per chip variant since embassy-nrf APIs differ across targets"],"tags":["embedded","panic","unwrap","macro","nrf"],"backgroundTag":"unwrap-panic","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}