{"record":{"id":"dee26cec36ed494c","repo":"embassy-rs/embassy","slug":"unwrap-of-failed-dee26c","errorCode":null,"errorMessage":"unwrap of `{}` failed: {}: {:?}","messagePattern":"unwrap of `(.+?)` failed: (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-net/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-net/src/fmt.rs#L192-L228","documentation":"This is the annotated variant of embassy-net's `unwrap!` macro (non-defmt build): `unwrap!(expr, \"message\", args...)`. On `Err`/`None` it panics with the stringified expression, the caller-provided context message (via `format_args!`), and the debug-formatted error. The extra message text identifies which internal operation failed.","triggerScenarios":"Any `unwrap!(expr, \"ctx\", ...)` call inside embassy-net whose `expr` evaluates to `Err(e)` or `None` — this macro arm (fmt.rs:210) fires only when extra context arguments are supplied at the call site.","commonSituations":"Embassy firmware running the embassy-net stack where an internal operation (queue send/receive, socket bookkeeping) fails while carrying a context label; typically seen during buffer starvation, closed resources, or race-y socket teardown.","solutions":["Use the context message in the panic output to pinpoint the failing `unwrap!(..., \"ctx\")` call in embassy-net sources.","Fix the root cause: enlarge socket/resource pools (`StackResources`), ensure sockets are not used after close, and check task wiring.","Enable the `defmt` feature for richer logging on target hardware.","Patch the driver locally to propagate the error rather than unwrap if failures are expected in your deployment."],"exampleFix":"// before\nlet slot = unwrap!(self.sockets.get(handle), \"get socket slot\");\n// after\nlet slot = self.sockets.get(handle).ok_or(Error::SocketClosed)?;","handlingStrategy":"validation","validationCode":"// Validate resource availability before operations that internally unwrap:\nif self.stack_resources_exhausted() { return Err(Error::ConnectionReset); }","typeGuard":"fn socket_is_open(s: &embassy_net::tcp::TcpSocket<'_>) -> bool { !matches!(s.state(), embassy_net::tcp::State::Closed) }","tryCatchPattern":"// Panic hook that captures the context message plus expression, then triggers a controlled restart of the network stack; panics cannot be caught in no_std firmware.","preventionTips":["Right-size StackResources and socket buffers for worst-case load.","Avoid sharing sockets/channels across tasks without proper ownership.","Enable defmt logging in development builds.","Audit embassy-net version upgrades for changed internal invariants."],"tags":["embedded","rust","panic","unwrap","networking"],"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"}