{"record":{"id":"b75bc43eefba8aed","repo":"tauri-apps/tauri","slug":"not-a-menuitem","errorCode":null,"errorMessage":"Not a MenuItem","messagePattern":"Not a MenuItem","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/src/menu/mod.rs","lineNumber":609,"sourceCode":"      muda::MenuItemKind::Icon(i) => Self::Icon(IconMenuItem(Arc::new(IconMenuItemInner::new(\n        app_handle, i,\n      )))),\n    }\n  }\n\n  /// Casts this item to a [`MenuItem`], and returns `None` if it wasn't.\n  pub fn as_menuitem(&self) -> Option<&MenuItem<R>> {\n    match self {\n      MenuItemKind::MenuItem(i) => Some(i),\n      _ => None,\n    }\n  }\n\n  /// Casts this item to a [`MenuItem`], and panics if it wasn't.\n  pub fn as_menuitem_unchecked(&self) -> &MenuItem<R> {\n    match self {\n      MenuItemKind::MenuItem(i) => i,\n      _ => panic!(\"Not a MenuItem\"),\n    }\n  }\n\n  /// Casts this item to a [`Submenu`], and returns `None` if it wasn't.\n  pub fn as_submenu(&self) -> Option<&Submenu<R>> {\n    match self {\n      MenuItemKind::Submenu(i) => Some(i),\n      _ => None,\n    }\n  }\n\n  /// Casts this item to a [`Submenu`], and panics if it wasn't.\n  pub fn as_submenu_unchecked(&self) -> &Submenu<R> {\n    match self {\n      MenuItemKind::Submenu(i) => i,\n      _ => panic!(\"Not a Submenu\"),\n    }\n  }","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/src/menu/mod.rs#L591-L627","documentation":"MenuItemKind is an enum over menu item kinds (MenuItem, Submenu, Predefined, Check, Icon). `as_menuitem_unchecked` performs an unchecked downcast to `MenuItem<R>` and panics with 'Not a MenuItem' when the variant is any other kind; the checked `as_menuitem` returns Option instead.","triggerScenarios":"Calling `as_menuitem_unchecked()` on a `MenuItemKind` obtained from a submenu, predefined item, check item, or icon item — e.g. iterating `menu.items()` and blindly casting each entry.","commonSituations":"Code that walks a menu's items and assumes all are regular MenuItems; event handlers storing items as MenuItemKind and later casting without remembering which variant was created; refactors that changed an item's kind without updating the cast.","solutions":["Use the safe `as_menuitem()` which returns `Option<&MenuItem<R>>` and handle the None case.","Match on the `MenuItemKind` enum explicitly and handle each variant.","Track item kinds at creation time (store the concrete `MenuItem<R>` handle) instead of casting later from the generic kind.","If unchecked is intentional, guard with `matches!(kind, MenuItemKind::MenuItem(_))` before casting."],"exampleFix":"// before\nlet item: &MenuItem<R> = kind.as_menuitem_unchecked(); // panics for other kinds\n// after\nif let Some(item) = kind.as_menuitem() {\n  // use item\n}","handlingStrategy":"type-guard","validationCode":"if matches!(kind, tauri::menu::MenuItemKind::MenuItem(_)) {\n  let item = kind.as_menuitem_unchecked();\n}","typeGuard":"fn as_menu_item<R: tauri::Runtime>(kind: &tauri::menu::MenuItemKind<R>) -> Option<&tauri::menu::MenuItem<R>> {\n  kind.as_menuitem()\n}","tryCatchPattern":null,"preventionTips":["Prefer the checked as_menuitem()/Option variant","Match on MenuItemKind variants when iterating heterogeneous item lists","Store concrete MenuItem handles where MenuItem APIs are needed"],"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"}