fix(menu): return error instead of panicking on unexpected ItemKind#15691
Open
krishpranav wants to merge 1 commit into
Open
fix(menu): return error instead of panicking on unexpected ItemKind#15691krishpranav wants to merge 1 commit into
krishpranav wants to merge 1 commit into
Conversation
| // `kind` comes straight from the (untrusted) IPC payload, so a kind | ||
| // outside the accepted set is reachable and must be a recoverable error | ||
| // rather than a panic. See tauri-apps/tauri#15686. | ||
| _ => Err(anyhow::anyhow!("unexpected menu item kind").into()), |
Contributor
There was a problem hiding this comment.
This is a breaking change, we'll need to either add a new macro or add an optional parameter to this macro
…auri-apps#15686) Menu plugin command handlers receive `kind` straight from the untrusted IPC payload and dispatch through the `do_menu_item!` macro. The macro's `defaults` kind set omits the root `Menu` variant, and several call sites further restrict the accepted kinds, so a `kind` outside the accepted set was reachable and hit `_ => unreachable!()`, aborting the whole process (e.g. `Menu.new({ items: [await Menu.new()] })` or a raw IPC call). Make the macro's fallback arm return a recoverable error (`anyhow::anyhow!("unexpected menu item kind").into()`), matching the manual `_ => return Err(...)` pattern already used elsewhere in the menu plugin. This fixes all nine `do_menu_item!` call sites at once. Add a regression test that drives the affected commands with mismatched kinds and asserts they return `Err` instead of panicking.
krishpranav
force-pushed
the
fix/menu-plugin-panic-15686
branch
from
July 10, 2026 07:33
f2c9c66 to
8e7a5a9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(menu): return error instead of panicking on unexpected ItemKind
Problem
Menu plugin commands take
kindstraight from the IPC payload and dispatch on it through thedo_menu_item!macro, whose accepted kind set never includes the rootMenuvariant (and some call sites narrow it further). Anything outside that set fell through to_ => unreachable!()and took the whole process down.Reachable from plain JS — the TS types don't stop it, and raw IPC ignores them:
Fix
do_menu_item!fallback arm fromunreachable!()to a recoverable error (anyhow::anyhow!("unexpected menu item kind").into()), matching the hand-written_ => return Err(...)arms already inmenu/plugin.rs. One macro change covers all nine call sites.Errinstead of panicking..changes/fix-menu-plugin-panic.mdwith valid covector front matter ("tauri": patch:bug,"tauri-macros": patch:bug).Testing
cargo fmt --check cargo clippy -p tauri -p tauri-macros --all-features -- -D warnings cargo test -p tauri --lib menu::plugin::testsThe regression test panics on
devand passes with this change.Before (fallback arm still
unreachable!()):After (this PR):
Visual Verification
App survives the repro (
examples/api)Ran the exact repro from the issue (
Menu.new({ items: [await Menu.new()] })). Ondevthe process aborts; with this change the call rejects withunexpected menu item kindand the window stays alive.Fixes #15686