{"record":{"id":"4343ddedfc903e4e","repo":"embassy-rs/embassy","slug":"unwrap-of-failed-4343dd","errorCode":null,"errorMessage":"unwrap of `{}` failed: {}: {:?}","messagePattern":"unwrap of `(.+?)` failed: (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-rp/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-rp/src/fmt.rs#L192-L228","documentation":"This panic comes from embassy-rp's custom `unwrap!` macro (defined via the `fmt` module's Try::into_result). It fires when an expression expected to be Ok/TryResult-success actually returned an Err, and prints the expression text, a user-supplied message, and the error's Debug representation. It is embassy's panic-with-context replacement for `.unwrap()` on embedded fallible APIs.","triggerScenarios":"Calling `unwrap!(some_fallible_expr, \"message\")` in embassy-rp code (e.g. GPIO, DMA, I2C setup helpers) where the inner expression returns Err — such as unwrap!(peri.gpio().into_pull_type_input(...)) style calls or any macro-based unwrap around a Result/TRY result.","commonSituations":"Invalid pin/peripheral configuration passed to a macro-wrapped initializer (wrong pin, double-use of a peripheral), or a HAL call that returned a ConfigError/Either error being blindly unwrapped in example-style code.","solutions":["Read the `{:?}` error value in the panic message; it names the underlying Err variant","Fix the configuration that made the unwrapped expression fail (wrong pin, pin already taken, invalid params)","Replace `unwrap!` with `match`/`?` or try_ variant APIs to handle the error instead of panicking","Check embassy-rp examples for the API you call to see required pin/feature setup"],"exampleFix":"// before\nlet pio = unwrap!(peri.pio(), \"pio error\");\n// after\nlet pio = match peri.pio() {\n    Ok(p) => p,\n    Err(e) => defmt::error!(\"pio setup failed: {:?}\", e),\n};","handlingStrategy":"try-catch","validationCode":"// validate before unwrap\nlet res = peri.fallible_init();\nif res.is_err() { defmt::error!(\"init failed: {:?}\", res.unwrap_err()); }","typeGuard":"fn is_ok<T>(r: &Result<T, E>) -> bool { r.is_ok() }","tryCatchPattern":"match embassy_rp::fmt::Try::into_result(expr) {\n    Ok(v) => use(v),\n    Err(e) => defmt::error!(\"expr failed: {:?}\", e),\n}","preventionTips":["Prefer try_/fallible APIs over unwrap! macros in production code","Log the Debug error value before deciding how to recover","Copy pin setup from the official embassy examples for your board"],"tags":["panic","embedded","unwrap","rust"],"backgroundTag":"invalid-argument-value","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"}