{"record":{"id":"b1a502ffd503c990","repo":"tauri-apps/tauri","slug":"not-a-submenu","errorCode":null,"errorMessage":"Not a Submenu","messagePattern":"Not a Submenu","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/src/menu/mod.rs","lineNumber":625,"sourceCode":"    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  }\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  }","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/src/menu/mod.rs#L607-L643","documentation":"`as_submenu_unchecked` downcasts a `MenuItemKind` to `Submenu<R>` and panics with 'Not a Submenu' when the variant is a plain MenuItem, Predefined, Check, or Icon item. The safe counterpart `as_submenu` returns Option.","triggerScenarios":"Calling `as_submenu_unchecked()` on a MenuItemKind that is not `MenuItemKind::Submenu` — typically when iterating menu items and assuming each is a submenu to add children to it.","commonSituations":"Building nested menus dynamically where some items are plain MenuItems but the code casts all to Submenu; retrieving an item by id that was changed to a MenuItem in a refactor; handling menu events with the wrong stored kind.","solutions":["Use the checked `as_submenu()` returning `Option<&Submenu<R>>` and handle None.","Pattern-match on `MenuItemKind::Submenu(s)` explicitly before using submenu APIs.","Keep concrete `Submenu<R>` handles where submenu APIs are needed instead of round-tripping through MenuItemKind.","Guard with `matches!(kind, MenuItemKind::Submenu(_))` if the unchecked variant must stay."],"exampleFix":"// before\nlet sub: &Submenu<R> = kind.as_submenu_unchecked();\nsub.append(&item)?;\n// after\nif let Some(sub) = kind.as_submenu() {\n  sub.append(&item)?;\n} else { eprintln!(\"item is not a submenu\"); }","handlingStrategy":"type-guard","validationCode":"if matches!(kind, tauri::menu::MenuItemKind::Submenu(_)) {\n  let sub = kind.as_submenu_unchecked();\n}","typeGuard":"fn as_submenu<R: tauri::Runtime>(kind: &tauri::menu::MenuItemKind<R>) -> Option<&tauri::menu::Submenu<R>> {\n  kind.as_submenu()\n}","tryCatchPattern":null,"preventionTips":["Use as_submenu() instead of the unchecked variant","Match MenuItemKind::Submenu explicitly before appending children","Keep Submenu handles in app state rather than re-casting generic kinds"],"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"}