{"record":{"id":"262e859b84aa93fb","repo":"Unity-Technologies/UnityCsReference","slug":"command-id-does-not-exist","errorCode":null,"errorMessage":"Command {id} does not exist","messagePattern":"Command (.+?) does not exist","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Commands/CommandService.cs","lineNumber":191,"sourceCode":"                {\n                    if (commands.Exists(c => c.id == attr.id))\n                    {\n                        Debug.LogWarning($\"There is already a command with the ID {attr.id}. \" +\n                            \"Commands need to have a unique ID, i.e. \\\"Unity/Category/Command_42\\\".\");\n                        continue;\n                    }\n\n                    commands.Add(new Command { id = attr.id, label = attr.label ?? attr.id, hint = attr.hint, handler = callback, managed = true });\n                }\n            }\n\n            return commands;\n        }\n\n        private static object ExecuteCommand(string id, CommandHint hint, object[] args)\n        {\n            if (!Exists(id))\n                throw new ArgumentException($\"Command {id} does not exist\", nameof(id));\n\n            var command = s_Commands[id];\n\n            if ((command.hint & hint) == 0)\n                throw new ArgumentException($\"Command ({id}, {command.hint}) does not match the hinting {hint}\", nameof(id));\n\n            var context = new CommandExecuteContext { hint = hint, args = args, result = null };\n            command.handler(context);\n            return context.result;\n        }\n    }\n}\n","sourceCodeStart":173,"sourceCodeEnd":204,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Commands/CommandService.cs#L173-L204","documentation":"ArgumentException thrown by CommandService.ExecuteCommand (private) when Exists(id) is false. ExecuteCommand is invoked to run a command by id with a CommandHint and args; an unregistered id cannot resolve to a handler. Unlike GetCommandLabel, this is on the execution path (menu/shortcut invocation).","triggerScenarios":"Dispatching execution for a command id that is not registered — e.g. a menu item or key binding referencing a removed/renamed command, or invoking before attributes are scanned.","commonSituations":"Stale key bindings or menu layouts referencing commands removed in a newer Unity/package version; invoking a command whose owning package is disabled; timing issues where ExecuteCommand runs before OnCodeLoaded populated s_Commands.","solutions":["Guard execution with Exists(id) and skip/no-op if missing.","Refresh or rebuild the menu/shortcut binding table after package/version changes.","Ensure command-execution dispatch only runs after command initialization."],"exampleFix":"// before\nCommandService.Execute(id, hint, args);\n\n// after\nif (CommandService.Exists(id))\n    CommandService.Execute(id, hint, args);","handlingStrategy":"validation","validationCode":"if (!CommandService.Exists(id)) return;\nCommandService.Execute(id, hint, args);","typeGuard":null,"tryCatchPattern":"try { CommandService.Execute(id, hint, args); }\ncatch (ArgumentException ex) { /* unknown command; log and skip */ }","preventionTips":["Guard execution with Exists.","Rebuild menu/shortcut tables after version/package changes.","Dispatch only after command initialization."],"tags":["unity-editor","commands","argument-validation","dispatch"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}