{"record":{"id":"a896018d17473718","repo":"leptos-rs/leptos","slug":"called-unwrap-variant-on-a-non-variant-v","errorCode":null,"errorMessage":"called `unwrap_{variant}()` on a non-`{variant}` variant of `{name}`","messagePattern":"called `unwrap_(.+?)\\(\\)` on a non-`(.+?)` variant of `(.+?)`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"either_of/src/lib.rs","lineNumber":88,"sourceCode":"\n                    pub fn [<as_ $variant:lower>](&self) -> Option<&$ty> {\n                        match self {\n                            $name::$variant(inner) => Some(inner),\n                            _ => None,\n                        }\n                    }\n\n                    pub fn [<as_ $variant:lower _mut>](&mut self) -> Option<&mut $ty> {\n                        match self {\n                            $name::$variant(inner) => Some(inner),\n                            _ => None,\n                        }\n                    }\n\n                    pub fn [<unwrap_ $variant:lower>](self) -> $ty {\n                        match self {\n                            $name::$variant(inner) => inner,\n                            _ => panic!(concat!(\n                                \"called `unwrap_\", stringify!([<$variant:lower>]), \"()` on a non-`\", stringify!($variant), \"` variant of `\", stringify!($name), \"`\"\n                            )),\n                        }\n                    }\n\n                    pub fn [<into_ $variant:lower>](self) -> Result<$ty, Self> {\n                        match self {\n                            $name::$variant(inner) => Ok(inner),\n                            _ => Err(self),\n                        }\n                    }\n                )+\n            }\n        }\n\n        impl<$($ty),+> Display for $name<$($ty),+>\n        where\n            $($ty: Display,)+","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/either_of/src/lib.rs#L70-L106","documentation":"Generated Either enum types provide typed unwrap_<variant>() methods; calling one on an instance holding a different variant panics with this message naming the expected variant and enum. It is a misuse-of-sum-type error: the caller assumed the wrong side of the either.","triggerScenarios":"Calling e.g. Either::Left(v).unwrap_right() (or unwrap_left on a Right) on a generated EitherOfN enum; the message is built by the macro with stringify!($variant)/stringify!($name).","commonSituations":"View rendering code where a conditional switched which branch of Either is produced (e.g. a show/if changed at runtime) and a downstream unwrap assumes the other branch; refactors that reorder enum variants.","solutions":["Match on the enum instead of unwrapping, handling both variants explicitly.","Use the generated into_<variant>() (returns Result) to attempt conversion safely.","If you must unwrap, first check with the corresponding is_<variant>-style or pattern-match guard."],"exampleFix":"// before\nlet value = either.unwrap_left(); // panics when it is Right\n// after\nlet value = match either {\n    Either::Left(v) => v,\n    Either::Right(v) => v,\n};","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn as_left<T, R>(e: Either<T, R>) -> Option<T> {\n    match e { Either::Left(v) => Some(v), _ => None }\n}","tryCatchPattern":"// Rust panics are not catchable with try/catch; avoid via match:\nmatch either {\n    Either::Left(v) => handle_left(v),\n    Either::Right(v) => handle_right(v),\n}","preventionTips":["Never unwrap Either variants in view code; match both branches.","Prefer into_left()/into_right() which return Result.","If logic only applies to one variant, restructure so that variant is the only one produced."],"tags":["enum","unwrap","panic","view"],"backgroundTag":"unwrap-on-wrong-enum-variant","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}