{"record":{"id":"4aa45bd1f1a28f9a","repo":"tauri-apps/tauri","slug":"not-a-checkmenuitem","errorCode":null,"errorMessage":"Not a CheckMenuItem","messagePattern":"Not a CheckMenuItem","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/src/menu/mod.rs","lineNumber":657,"sourceCode":"    match self {\n      MenuItemKind::Predefined(i) => i,\n      _ => panic!(\"Not a PredefinedMenuItem\"),\n    }\n  }\n\n  /// Casts this item to a [`CheckMenuItem`], and returns `None` if it wasn't.\n  pub fn as_check_menuitem(&self) -> Option<&CheckMenuItem<R>> {\n    match self {\n      MenuItemKind::Check(i) => Some(i),\n      _ => None,\n    }\n  }\n\n  /// Casts this item to a [`CheckMenuItem`], and panics if it wasn't.\n  pub fn as_check_menuitem_unchecked(&self) -> &CheckMenuItem<R> {\n    match self {\n      MenuItemKind::Check(i) => i,\n      _ => panic!(\"Not a CheckMenuItem\"),\n    }\n  }\n\n  /// Casts this item to a [`IconMenuItem`], and returns `None` if it wasn't.\n  pub fn as_icon_menuitem(&self) -> Option<&IconMenuItem<R>> {\n    match self {\n      MenuItemKind::Icon(i) => Some(i),\n      _ => None,\n    }\n  }\n\n  /// Casts this item to a [`IconMenuItem`], and panics if it wasn't.\n  pub fn as_icon_menuitem_unchecked(&self) -> &IconMenuItem<R> {\n    match self {\n      MenuItemKind::Icon(i) => i,\n      _ => panic!(\"Not an IconMenuItem\"),\n    }\n  }","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/src/menu/mod.rs#L639-L675","documentation":"`as_check_menuitem_unchecked` downcasts a `MenuItemKind` to `CheckMenuItem<R>` and panics with 'Not a CheckMenuItem' if the variant is a plain item, submenu, predefined, or icon item. The checked `as_check_menuitem` returns Option and is the recommended alternative.","triggerScenarios":"Calling `as_check_menuitem_unchecked()` on a kind that is not `MenuItemKind::Check` — commonly when handling a menu event by id and casting the stored kind assuming it was created with `check(...)`.","commonSituations":"Toggling checkbox state from a menu event handler where the item was later replaced by a plain MenuItem or IconMenuItem; iterating heterogeneous menu items to read `is_checked()`; version refactors changing item constructors.","solutions":["Use the safe `as_check_menuitem()` and handle the None case.","Match on `MenuItemKind::Check(c)` explicitly before reading/writing check state.","Retain the concrete `CheckMenuItem<R>` handle in application state to avoid casting by kind later.","If the unchecked cast stays, pre-check with `matches!(kind, MenuItemKind::Check(_))`."],"exampleFix":"// before\nlet chk: &CheckMenuItem<R> = kind.as_check_menuitem_unchecked();\nchk.set_checked(true)?;\n// after\nif let Some(chk) = kind.as_check_menuitem() {\n  chk.set_checked(true)?;\n}","handlingStrategy":"type-guard","validationCode":"if matches!(kind, tauri::menu::MenuItemKind::Check(_)) {\n  let chk = kind.as_check_menuitem_unchecked();\n}","typeGuard":"fn as_check<R: tauri::Runtime>(kind: &tauri::menu::MenuItemKind<R>) -> Option<&tauri::menu::CheckMenuItem<R>> {\n  kind.as_check_menuitem()\n}","tryCatchPattern":null,"preventionTips":["Use the checked as_check_menuitem() before touching check state","Keep the concrete CheckMenuItem handle in state for event handlers","Re-verify item kinds after refactors that change menu construction"],"tags":["rust","tauri","menu","panic"],"backgroundTag":"invalid-enum-value","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}