{"record":{"id":"f76e0b1c766aa79c","repo":"chocolatey/choco","slug":"missing-required-value-for-option-0","errorCode":null,"errorMessage":"Missing required value for option '{0}'.","messagePattern":"Missing required value for option '(.+?)'\\.","errorType":"exception","errorClass":"OptionException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure/commandline/Options.cs","lineNumber":214,"sourceCode":"\t\tvoid IList.RemoveAt (int index)             {(values as IList).RemoveAt (index);}\r\n\t\tbool IList.IsFixedSize                      {get {return false;}}\r\n\t\tobject IList.this [int index]               {get {return this [index];} set {(values as IList)[index] = value;}}\r\n\t\t#endregion\r\n\r\n\t\t#region IList<T>\r\n\t\tpublic int IndexOf (string item)            {return values.IndexOf (item);}\r\n\t\tpublic void Insert (int index, string item) {values.Insert (index, item);}\r\n\t\tpublic void RemoveAt (int index)            {values.RemoveAt (index);}\r\n\r\n\t\tprivate void AssertValid (int index)\r\n\t\t{\r\n\t\t\tif (c.Option == null)\r\n\t\t\t\tthrow new InvalidOperationException (\"OptionContext.Option is null.\");\r\n\t\t\tif (index >= c.Option.MaxValueCount)\r\n\t\t\t\tthrow new ArgumentOutOfRangeException (\"index\");\r\n\t\t\tif (c.Option.OptionValueType == OptionValueType.Required &&\r\n\t\t\t\t\tindex >= values.Count)\r\n\t\t\t\tthrow new OptionException (string.Format (\r\n\t\t\t\t\t\t\tc.OptionSet.MessageLocalizer (\"Missing required value for option '{0}'.\"), c.OptionName),\r\n\t\t\t\t\t\tc.OptionName);\r\n\t\t}\r\n\r\n\t\tpublic string this [int index] {\r\n\t\t\tget {\r\n\t\t\t\tAssertValid (index);\r\n\t\t\t\treturn index >= values.Count ? null : values [index];\r\n\t\t\t}\r\n\t\t\tset {\r\n\t\t\t\tvalues [index] = value;\r\n\t\t\t}\r\n\t\t}\r\n\t\t#endregion\r\n\r\n\t\tpublic List<string> ToList ()\r\n\t\t{\r\n\t\t\treturn new List<string> (values);\r","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure/commandline/Options.cs#L196-L232","documentation":"Thrown by Mono.Options OptionSet when an option declared with OptionValueType.Required is accessed but fewer values were supplied on the command line than MaxValueCount requires. AssertValid detects that the required value slot (index) is beyond what was actually provided and raises an OptionException naming the offending option.","triggerScenarios":"Invoking a Chocolatey command line like `--cache-location` (a required-value option) at the end of the argument list with no following value, or where the value was consumed by another token. The indexer reaches a required position with values.Count not large enough.","commonSituations":"Quoting/escaping mistakes that detach a value from its flag, or option ordering where a later flag swallows the intended value. Auto-generated command lines from scripts that omit a value under certain conditions.","solutions":["Re-run with the missing value supplied directly after the option: --cache-location <path>.","Quote the value as a single argument if it contains spaces: \"--cache-location=<path with spaces>\".","Inspect the full command line for flags accidentally placed where they consume the value (e.g. --limitoutput directly before a value-needing option)."],"exampleFix":"// before\nchoco install pkg --cache-location\n\n// after\nchoco install pkg --cache-location C:/choco/cache","handlingStrategy":"try-catch","validationCode":"// Before invoking choco as a process, validate that every required-value option\n// is followed by a non-flag token.\nstatic bool HasValueForRequiredOption(string[] args, string flag)\n{\n    for (int i = 0; i < args.Length; i++)\n        if (args[i] == flag || args[i].StartsWith(flag + \"=\"))\n            return args[i].Contains(\"=\") || (i + 1 < args.Length && !args[i + 1].StartsWith(\"-\"));\n    return true; // flag absent, nothing to satisfy\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    optionSet.Parse(args);\n}\ncatch (OptionException ex) when (ex.Message.Contains(\"Missing required value\"))\n{\n    Console.Error.WriteLine(\"Argument error: \" + ex.Message);\n    Console.Error.WriteLine(\"Supply a value for each listed option.\");\n    Environment.Exit(1);\n}","preventionTips":["Always pair a required-value option with its value in the same quoted token (--flag=value).","In scripts, assert no required-value flag is the last token before parsing."],"tags":["commandline","mono-options","argument-parsing","required-value"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}