{"record":{"id":"4883f9356e454eb7","repo":"chocolatey/choco","slug":"cannot-bundle-unregistered-option-0","errorCode":null,"errorMessage":"Cannot bundle unregistered option '{0}'.","messagePattern":"Cannot bundle unregistered option '(.+?)'\\.","errorType":"validation","errorClass":"OptionException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure/commandline/Options.cs","lineNumber":896,"sourceCode":"\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n        private bool ParseBundledValue(string f, string n, OptionContext c)\r\n        {\r\n            IDictionary<Option, string> normalOptions = new Dictionary<Option, string>();\r\n            if (f != \"-\")\r\n                return false;\r\n            for (int i = 0; i < n.Length; ++i)\r\n            {\r\n                Option p;\r\n                string opt = f + n[i].ToString();\r\n                string rn = n[i].ToString();\r\n                if (!Contains(rn))\r\n                {\r\n                    if (i == 0)\r\n                        return false;\r\n                    throw new OptionException(string.Format(_localizer(\r\n                                    \"Cannot bundle unregistered option '{0}'.\"), opt), opt);\r\n                }\r\n                p = this[rn];\r\n\r\n                switch (p.OptionValueType)\r\n                {\r\n                    case OptionValueType.None:\r\n                        normalOptions.Add(p, opt);\r\n                        break;\r\n                    case OptionValueType.Optional:\r\n                    case OptionValueType.Required:\r\n                        {\r\n                            string v = n.Substring(i + 1);\r\n                            c.Option = p;\r\n                            c.OptionName = opt;\r\n                            ParseValue(v.Length != 0 ? v : null, c);\r\n                            return true;\r\n                        }\r","sourceCodeStart":878,"sourceCodeEnd":914,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure/commandline/Options.cs#L878-L914","documentation":"Thrown by Mono.Options' bundle parser when a clustered short-option string (e.g. -abc) contains a character that is not a registered option. Bundling is only allowed when every character in the cluster maps to a known option; the first unregistered character (after at least one valid one) triggers this OptionException naming the offending -x token.","triggerScenarios":"Passing something like -vxy where -v is valid but -x/-y are not registered, and the parser is in bundling mode (input starts with a lone -). The i == 0 early-return means a wholly-unregistered cluster returns false (treated as a value) rather than throwing, so the throw only happens for a mixed cluster.","commonSituations":"Typos in combined flags, or assuming a flag exists that belongs to a different Chocolatey command. Version upgrades that renamed or removed a short flag leave scripts with stale clusters.","solutions":["Split the cluster into individual flags and run `choco <command> -h` to confirm each short flag is registered for that command.","Remove the unregistered character from the cluster, or replace it with the correct flag name.","Prefer long-form flags (--verbose) in scripts for resilience against short-flag renames."],"exampleFix":"// before (x not registered)\nchoco search -vx query\n\n// after\nchoco search -v query","handlingStrategy":"validation","validationCode":"// Validate each character in a bundled short-options cluster against registered options.\nstring cluster = \"-vx\";\nvar registered = new HashSet<string>(new[] { \"v\" }); // known short names for the command\nforeach (char ch in cluster.Substring(1))\n    if (!registered.Contains(ch.ToString()))\n        throw new ArgumentException(\"Unregistered short option '-\" + ch + \"' in cluster '\" + cluster + \"'.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    optionSet.Parse(args);\n}\ncatch (OptionException ex) when (ex.Message.Contains(\"Cannot bundle unregistered option\"))\n{\n    Console.Error.WriteLine(ex.Message);\n    Console.Error.WriteLine(\"Run choco <command> -h to list valid short flags.\");\n    Environment.Exit(1);\n}","preventionTips":["In scripts, prefer long-form flags to avoid fragility from short-flag renames.","Confirm every character in a short-option cluster is a registered flag for the current command."],"tags":["commandline","mono-options","bundling","argument-parsing"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}