{"record":{"id":"7d5317d64ca206d4","repo":"linebender/druid","slug":"command-must-carry-a-contextmenu-application-st","errorCode":null,"errorMessage":"{} command must carry a ContextMenu<application state>.","messagePattern":"(.+?) command must carry a ContextMenu<application state>\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"druid/src/win_handler.rs","lineNumber":447,"sourceCode":"\n        if let Some(win) = self.windows.get_mut(source_id) {\n            win.event(&mut self.command_queue, event, &mut self.data, &self.env)\n        } else {\n            Handled::No\n        }\n    }\n\n    fn show_context_menu(&mut self, window_id: WindowId, cmd: &Command) {\n        if let Some(win) = self.windows.get_mut(window_id) {\n            match cmd\n                .get_unchecked(sys_cmd::SHOW_CONTEXT_MENU)\n                .take()\n                .and_then(|b| b.downcast::<ContextMenu<T>>().ok())\n            {\n                Some(menu) => {\n                    win.show_context_menu(menu.menu, menu.location, &self.data, &self.env)\n                }\n                None => panic!(\n                    \"{} command must carry a ContextMenu<application state>.\",\n                    sys_cmd::SHOW_CONTEXT_MENU\n                ),\n            }\n        }\n    }\n\n    fn do_update(&mut self) {\n        // we send `update` to all windows, not just the active one:\n        for window in self.windows.iter_mut() {\n            window.update(&mut self.command_queue, &self.data, &self.env);\n            if let Some(focus_change) = window.ime_focus_change.take() {\n                // we need to call this outside of the borrow, so we create a\n                // closure that takes the correct window handle. yes, it feels\n                // weird.\n                let handle = window.handle.clone();\n                let f = Box::new(move || handle.set_focused_text_field(focus_change));\n                self.ime_focus_change = Some(f);","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/linebender/druid/blob/0f8b1195e4e073f9597f2865299c3d18f8e4005f/druid/src/win_handler.rs#L429-L465","documentation":"When druid's AppDelegate/handler processes the SHOW_CONTEXT_MENU command, the command's payload must be a `ContextMenu<application state>` object. If the command arrives without such a payload (wrong type or none at all), the downcast fails and the handler panics, since a context menu cannot be shown without its menu structure.","triggerScenarios":"Submitting the `sys_cmd::SHOW_CONTEXT_MENU` command with `to(...)` but no payload, or with a payload that is not `ContextMenu<T>` (e.g. a raw Menu, wrong generic type, or a different struct).","commonSituations":"Hand-crafting the SHOW_CONTEXT_MENU command instead of using the `ctx.show_context_menu(menu)` helper; changing the application's state type `T` so an older payload no longer downcasts; passing `ContextMenu<OtherState>` created under a different state type.","solutions":["Use the built-in helper `ctx.show_context_menu(menu, pos)` (or `show_context_menu` on the appropriate context) rather than submitting sys_cmd::SHOW_CONTEXT_MENU manually","If submitting manually, attach the payload: `.to(...)` is not enough — use a command that carries `ContextMenu<T>`, e.g. via the helper, so the downcast succeeds","Ensure the ContextMenu was created for the same application state type `T` as the running app"],"exampleFix":"// before\nctx.submit_command(Command::new(sys_cmd::SHOW_CONTEXT_MENU, None, ctx.window_id()));\n// after\nctx.show_context_menu(menu, ctx.to_point(pos)); // payload wired correctly","handlingStrategy":"validation","validationCode":"// Verify payload type before submitting a SHOW_CONTEXT_MENU command manually\nlet cmd = Command::new(\n    sys_cmd::SHOW_CONTEXT_MENU,\n    Some(Box::new(ContextMenu::new(menu, pos))), // payload must be ContextMenu<T>\n    ctx.window_id(),\n);\nctx.submit_command(cmd);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer ctx.show_context_menu() over manual command submission","Keep the payload's generic type equal to the app's state type T","Regenerate ContextMenu payloads after changing the state type"],"tags":["druid","rust","gui","command-payload","downcast","panic"],"backgroundTag":"missing-required-argument","analyzedSha":"0f8b1195e4e073f9597f2865299c3d18f8e4005f","analyzedAt":"2026-09-10T14:27:34.582Z","contentChangedAt":"2026-09-10T14:27:34.582Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}