{"record":{"id":"95154c55117aaab0","repo":"Unity-Technologies/UnityCsReference","slug":"no-command-with-id-commandid-exists","errorCode":null,"errorMessage":"No command with id {commandId} exists","messagePattern":"No command with id (.+?) exists","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Commands/CommandService.cs","lineNumber":106,"sourceCode":"        }\n\n        [AutoStaticsCleanupOnCodeReload]\n        private static Dictionary<string, Command> s_Commands;\n        [NoAutoStaticsCleanup] // Fixed single-element sentinel args array; holds only a null, no user-code references, safe to persist across reload.\n        private static readonly object[] k_DefaultArgs = { null };\n\n        [OnCodeLoaded]\n        static void Initialize()\n        {\n#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.\n            s_Commands = ScanAttributes().ToDictionary(c => c.id, c => c);\n#pragma warning restore UA2001\n        }\n\n        public static string GetCommandLabel(string commandId)\n        {\n            if (!Exists(commandId))\n                throw new ArgumentException($\"No command with id {commandId} exists\", nameof(commandId));\n\n            return s_Commands[commandId].label;\n        }\n\n        public static void RegisterCommand(string id, string label, CommandHandler handler, CommandHint hint = CommandHint.Any)\n        {\n            if (Exists(id))\n                throw new ArgumentException($\"A command with id {id} already exists\", nameof(id));\n\n            s_Commands[id] = new Command {id = id, label = label ?? id, hint = hint, handler = handler, managed = false};\n        }\n\n        public static void RegisterCommand(string id, CommandHandler handler, CommandHint hint = CommandHint.Any)\n        {\n            RegisterCommand(id, id, handler, hint);\n        }\n\n        public static bool UnregisterCommand(string id)","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Commands/CommandService.cs#L88-L124","documentation":"ArgumentException thrown by CommandService.GetCommandLabel when no command with the given commandId is registered. Commands are populated at code-load time via ScanAttributes() into s_Commands (id-keyed) and extended via RegisterCommand; GetCommandLabel indexes that dictionary, so an unknown id is a usage error.","triggerScenarios":"Calling CommandService.GetCommandLabel(commandId) for an id never registered (not declared via attribute and not registered at runtime). Also when the id string casing/spelling differs from the registered one.","commonSituations":"Referencing a menu/shortcut command id that was removed, renamed, or lives in an assembly that did not load. Typing the id string differently from the declared attribute. Querying before OnCodeLoaded initialization completes.","solutions":["Call CommandService.Exists(commandId) before GetCommandLabel and handle the missing case.","Verify the id matches the registered Command attribute/registration exactly (case-sensitive).","Ensure the owning assembly is loaded before querying."],"exampleFix":"// before\nvar label = CommandService.GetCommandLabel(id);\n\n// after\nvar label = CommandService.Exists(id) ? CommandService.GetCommandLabel(id) : null;","handlingStrategy":"validation","validationCode":"if (!CommandService.Exists(commandId)) return null;\nreturn CommandService.GetCommandLabel(commandId);","typeGuard":null,"tryCatchPattern":"try { return CommandService.GetCommandLabel(id); }\ncatch (ArgumentException) { return null; }","preventionTips":["Call Exists before GetCommandLabel.","Match command ids exactly (case-sensitive).","Ensure the owning assembly is loaded before querying."],"tags":["unity-editor","commands","argument-validation","dictionary-lookup"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}