{"record":{"id":"84bc622943d20ed9","repo":"embassy-rs/embassy","slug":"unwrap-of-failed-84bc62","errorCode":null,"errorMessage":"unwrap of `{}` failed: {}: {:?}","messagePattern":"unwrap of `(.+?)` failed: (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-net-wiznet/src/fmt.rs","lineNumber":197,"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":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-net-wiznet/src/fmt.rs#L179-L215","documentation":"This is the context-carrying variant of embassy-net-wiznet's `unwrap!` macro (non-defmt build): `unwrap!(expr, \"message\", args...)`. When `expr` is `Err` or `None`, it panics printing the stringified expression, the caller-supplied context message, and the debug-formatted error value. The extra `format_args!` text comes from the call site to pinpoint which operation failed.","triggerScenarios":"Any call to `unwrap!(expr, \"ctx\", ...)` in the wiznet W5500 driver where `expr` yields `Err(e)` or `None` — the second panic arm at fmt.rs:197 fires only when the caller passed extra message arguments.","commonSituations":"Embedded firmware using the Wiznet Ethernet driver hits a failed SPI/queue/register operation while a context label (e.g. \"spi transfer\", \"fifo read\") is attached, usually during bring-up of new hardware or after a bus glitch.","solutions":["Read the context message in the panic output to locate the failing operation, then find that `unwrap!(..., \"ctx\")` call in embassy-net-wiznet sources.","Fix the root cause: verify SPI wiring, clock speed, chip select, and that the W5500 is properly reset and powered.","Handle the error path explicitly at the call site instead of unwrapping if failures are expected in your environment.","Enable `defmt` logging to get better diagnostics on constrained targets."],"exampleFix":"// before\nlet reg = unwrap!(self.read_reg(Reg::PHYCFGR), \"read phycfgr\");\n// after\nlet reg = self.read_reg(Reg::PHYCFGR).map_err(|_| Error::Spi)?;","handlingStrategy":"try-catch","validationCode":"// Pre-check the operation the context label names, e.g. SPI bus:\nif !self.spi_ok().await { return Err(Error::Spi); }","typeGuard":"fn is_ok<T, E>(r: &Result<T, E>) -> bool { r.is_ok() }","tryCatchPattern":"// Use a panic hook that records the context message (second field of the panic) to identify the failing subsystem, then perform a safe device reset.","preventionTips":["Treat the panic's context message as the lead and audit that specific driver path.","Stress-test SPI bus under EMI/long traces; add error retry at the board level.","Keep embassy-net-wiznet and embassy-net versions in sync.","Enable defmt for richer failure diagnostics."],"tags":["embedded","rust","panic","unwrap","network-driver"],"backgroundTag":"internal-invariant-violation","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"}