{"record":{"id":"a80cd64905b2fbc2","repo":"chocolatey/choco","slug":"package-name-is-required-please-pass-at-least-one-a80cd6","errorCode":null,"errorMessage":"Package name is required. Please pass at least one package name to upgrade.","messagePattern":"Package name is required\\. Please pass at least one package name to upgrade\\.","errorType":"validation","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs","lineNumber":279,"sourceCode":"                ;\r\n        }\r\n\r\n        public virtual void ParseAdditionalArguments(IList<string> unparsedArguments, ChocolateyConfiguration configuration)\r\n        {\r\n            configuration.Input = string.Join(\" \", unparsedArguments);\r\n            configuration.PackageNames = string.Join(ApplicationParameters.PackageNamesSeparator.ToStringSafe(), unparsedArguments.Where(arg => !arg.StartsWith(\"-\")));\r\n\r\n            if (configuration.RegularOutput)\r\n            {\r\n                WarnForRemovedOptions(unparsedArguments.Where(arg => arg.StartsWith(\"-\")), _removedOptions);\r\n            }\r\n        }\r\n\r\n        public virtual void Validate(ChocolateyConfiguration configuration)\r\n        {\r\n            if (string.IsNullOrWhiteSpace(configuration.PackageNames))\r\n            {\r\n                throw new ApplicationException(\"Package name is required. Please pass at least one package name to upgrade.\");\r\n            }\r\n\r\n            if (configuration.ForceDependencies && !configuration.Force)\r\n            {\r\n                throw new ApplicationException(\"Force dependencies can only be used with force also turned on.\");\r\n            }\r\n\r\n            if (!string.IsNullOrWhiteSpace(configuration.Input))\r\n            {\r\n                var unparsedOptionsAndPackages = configuration.Input.Split(new[] { \" \" }, StringSplitOptions.RemoveEmptyEntries);\r\n                if (!configuration.Information.IsLicensedVersion)\r\n                {\r\n                    foreach (var argument in unparsedOptionsAndPackages.OrEmpty())\r\n                    {\r\n                        var arg = argument.ToLowerSafe();\r\n                        if (arg.StartsWith(\"-dir\") || arg.StartsWith(\"--dir\") || arg.StartsWith(\"-install\") || arg.StartsWith(\"--install\"))\r\n                        {\r\n                            throw new ApplicationException(\"It appears you are attempting to use options that may be only available in licensed versions of Chocolatey ('{0}'). There may be ways in the open source edition to achieve what you are looking to do. Please remove the argument and consult the documentation.\".FormatWith(arg));\r","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs#L261-L297","documentation":"Thrown by ChocolateyUpgradeCommand.Validate() when configuration.PackageNames is null or whitespace. The 'choco upgrade' command requires at least one package name to be specified as a positional argument; unlike 'choco upgrade all', there is no default behavior when no target is given. This is a pre-execution validation gate that fires before any source or package resolution begins.","triggerScenarios":"Running 'choco upgrade' with no positional arguments (e.g. only flags like 'choco upgrade --force'). Calling the Validate() method programmatically on a ChocolateyConfiguration object where PackageNames was never set. All positional arguments starting with '-' are filtered out before assignment to PackageNames, so passing only options yields an empty PackageNames.","commonSituations":"User runs 'choco upgrade' expecting it to upgrade everything (the correct command is 'choco upgrade all'). User passes only options like 'choco upgrade -y' forgetting the package name. Script automation passes an empty or whitespace variable as the package argument. All arguments happen to start with '-' and get filtered out by the unparsedArguments.Where(arg => !arg.StartsWith(\"-\")) filter.","solutions":["Specify at least one package name: 'choco upgrade <packageName>'","To upgrade all packages use: 'choco upgrade all'","If scripting, verify the package name variable is non-empty before invoking the command","Ensure no leading '-' characters on package names that would cause them to be filtered as options"],"exampleFix":"// before\nchoco upgrade --force\n\n// after\nchoco upgrade mypackage --force\n// or upgrade everything:\nchoco upgrade all --force","handlingStrategy":"validation","validationCode":"// Validate before calling the command or API\nif (string.IsNullOrWhiteSpace(configuration.PackageNames))\n{\n    Console.Error.WriteLine(\"Package name is required. Pass at least one package name.\");\n    return;\n}\n// Or for CLI: ensure args has at least one non-dash argument\nvar packages = args.Where(a => !a.StartsWith(\"-\")).ToList();\nif (packages.Count == 0)\n{\n    Console.Error.WriteLine(\"Usage: choco upgrade <package-name> [options]\");\n    Environment.Exit(1);\n}","typeGuard":"public static bool HasValidPackageNames(ChocolateyConfiguration config)\n{\n    return !string.IsNullOrWhiteSpace(config?.PackageNames);\n}","tryCatchPattern":"try\n{\n    upgradeCommand.Validate(configuration);\n}\ncatch (ApplicationException ex) when (ex.Message.Contains(\"Package name is required\"))\n{\n    logger.Error(\"No package specified. Usage: choco upgrade <package> [--force]\");\n    // Prompt user or return error\n}","preventionTips":["Always include at least one package name as a positional argument in 'choco upgrade'","Use 'choco upgrade all' to upgrade every installed package","In scripts, validate the package name variable is non-empty before passing it to choco","Be aware that arguments starting with '-' are treated as options, not package names"],"tags":["validation","command-args","upgrade","package-management"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}