{"record":{"id":"ff15c3b317194c2b","repo":"tauri-apps/tauri","slug":"not-a-predefinedmenuitem","errorCode":null,"errorMessage":"Not a PredefinedMenuItem","messagePattern":"Not a PredefinedMenuItem","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/src/menu/mod.rs","lineNumber":641,"sourceCode":"    match self {\n      MenuItemKind::Submenu(i) => i,\n      _ => panic!(\"Not a Submenu\"),\n    }\n  }\n\n  /// Casts this item to a [`PredefinedMenuItem`], and returns `None` if it wasn't.\n  pub fn as_predefined_menuitem(&self) -> Option<&PredefinedMenuItem<R>> {\n    match self {\n      MenuItemKind::Predefined(i) => Some(i),\n      _ => None,\n    }\n  }\n\n  /// Casts this item to a [`PredefinedMenuItem`], and panics if it wasn't.\n  pub fn as_predefined_menuitem_unchecked(&self) -> &PredefinedMenuItem<R> {\n    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  }","sourceCodeStart":623,"sourceCodeEnd":659,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/src/menu/mod.rs#L623-L659","documentation":"`as_predefined_menuitem_unchecked` downcasts a `MenuItemKind` to `PredefinedMenuItem<R>` (separator, copy, paste, etc.) and panics with 'Not a PredefinedMenuItem' when the item is any other kind. The safe `as_predefined_menuitem` returns Option.","triggerScenarios":"Calling `as_predefined_menuitem_unchecked()` on a kind that is not `MenuItemKind::Predefined` — e.g. scanning menu items looking for separators while the collection contains plain menu items or submenus.","commonSituations":"Menu inspection/migration code that assumes uniform kinds; toggling predefined items by casting stored kinds that were actually regular MenuItems; automated menu tests iterating heterogeneous item lists.","solutions":["Use `as_predefined_menuitem()` returning `Option<&PredefinedMenuItem<R>>` instead of the unchecked cast.","Match explicitly on `MenuItemKind::Predefined(p)` and skip/handle other variants.","Store concrete `PredefinedMenuItem<R>` handles when you need predefined-item APIs later.","Filter the item collection by kind before performing predefined-specific operations."],"exampleFix":"// before\nlet pre: &PredefinedMenuItem<R> = kind.as_predefined_menuitem_unchecked();\n// after\nif let Some(pre) = kind.as_predefined_menuitem() {\n  // predefined-only API\n}","handlingStrategy":"type-guard","validationCode":"if matches!(kind, tauri::menu::MenuItemKind::Predefined(_)) {\n  let pre = kind.as_predefined_menuitem_unchecked();\n}","typeGuard":"fn as_predefined<R: tauri::Runtime>(kind: &tauri::menu::MenuItemKind<R>) -> Option<&tauri::menu::PredefinedMenuItem<R>> {\n  kind.as_predefined_menuitem()\n}","tryCatchPattern":null,"preventionTips":["Use as_predefined_menuitem() and skip non-predefined items","Filter collections by kind before predefined-only operations","Store PredefinedMenuItem handles if toggling later"],"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"}