{"record":{"id":"74c4ab612cd9182d","repo":"embassy-rs/embassy","slug":"unwrap-of-failed-74c4ab","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":202,"sourceCode":"    };\n}\n\n#[cfg(feature = \"defmt\")]\n#[collapse_debuginfo(yes)]\nmacro_rules! unwrap {\n    ($($x:tt)*) => {\n        ::defmt::unwrap!($($x)*)\n    };\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;","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-nrf/src/fmt.rs#L184-L220","documentation":"This is embassy's own `unwrap!` macro (in embassy-nrf/src/fmt.rs) panicking when the wrapped expression evaluates to Err (or None via `Try::into_result`). It exists so embedded firmware can unwrap Results/Options while still logging the expression text and error value. The panic message includes the original expression source (`{}` via stringify!) and the Debug-formatted error, so the actual failure cause is whatever the inner call returned.","triggerScenarios":"Any call site in embassy-nrf (or user code importing this macro) using `unwrap!(expr)` where expr returns an Err — e.g. `unwrap!(uarte.write(b\"x\"))` failing with a peripheral error, `unwrap!(slice.fill_bytes(...))`, failed IPC/channel receives, or invalid peripheral configuration returning Err at init.","commonSituations":"Wrong pin/peripheral configuration at init time; passing buffers violating driver invariants; interrupt or channel receive failures when a sender was dropped; calling driver methods with invalid enum values for the specific chip variant.","solutions":["Read the `{:?}` error in the panic message — it names the underlying Err that caused the unwrap to fail","Replace `unwrap!(...)` at the failing call site with explicit `match`/`?` handling and log or recover from the error","Check that the peripheral/config passed to the failing call is valid for your chip variant and feature flags","If it fails at init, verify pins, buffers, and clock configuration against the datasheet"],"exampleFix":"// before\nunwrap!(uarte.write(&buf).await);\n// after\nif let Err(e) = uarte.write(&buf).await {\n    defmt::error!(\"uarte write failed: {:?}\", e);\n    return;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Replace unwrap! with explicit handling:\n// match op() {\n//     Ok(v) => v,\n//     Err(e) => { defmt::error!(\"op failed: {:?}\", e); return Err(e); }\n// }","preventionTips":["Prefer `?` or explicit match over unwrap! in application code","Log the Debug error from the panic message to identify the root cause","Validate peripheral configs (pins, buffers, enums) before calls that unwrap","Add unit/integration tests for fallible driver calls on your exact chip variant"],"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"}