chocolatey/choco · error · ApplicationException

Package name is required. Please pass at least one package n

Error message

Package name is required. Please pass at least one package name to upgrade.

What it means

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.

Source

Thrown at src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs:279

                ;
        }

        public virtual void ParseAdditionalArguments(IList<string> unparsedArguments, ChocolateyConfiguration configuration)
        {
            configuration.Input = string.Join(" ", unparsedArguments);
            configuration.PackageNames = string.Join(ApplicationParameters.PackageNamesSeparator.ToStringSafe(), unparsedArguments.Where(arg => !arg.StartsWith("-")));

            if (configuration.RegularOutput)
            {
                WarnForRemovedOptions(unparsedArguments.Where(arg => arg.StartsWith("-")), _removedOptions);
            }
        }

        public virtual void Validate(ChocolateyConfiguration configuration)
        {
            if (string.IsNullOrWhiteSpace(configuration.PackageNames))
            {
                throw new ApplicationException("Package name is required. Please pass at least one package name to upgrade.");
            }

            if (configuration.ForceDependencies && !configuration.Force)
            {
                throw new ApplicationException("Force dependencies can only be used with force also turned on.");
            }

            if (!string.IsNullOrWhiteSpace(configuration.Input))
            {
                var unparsedOptionsAndPackages = configuration.Input.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (!configuration.Information.IsLicensedVersion)
                {
                    foreach (var argument in unparsedOptionsAndPackages.OrEmpty())
                    {
                        var arg = argument.ToLowerSafe();
                        if (arg.StartsWith("-dir") || arg.StartsWith("--dir") || arg.StartsWith("-install") || arg.StartsWith("--install"))
                        {
                            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));

View on GitHub (pinned to 0d5abdd10c)

Solutions

  1. Specify at least one package name: 'choco upgrade <packageName>'
  2. To upgrade all packages use: 'choco upgrade all'
  3. If scripting, verify the package name variable is non-empty before invoking the command
  4. Ensure no leading '-' characters on package names that would cause them to be filtered as options

Example fix

// before
choco upgrade --force

// after
choco upgrade mypackage --force
// or upgrade everything:
choco upgrade all --force
Defensive patterns

Strategy: validation

Validate before calling

// Validate before calling the command or API
if (string.IsNullOrWhiteSpace(configuration.PackageNames))
{
    Console.Error.WriteLine("Package name is required. Pass at least one package name.");
    return;
}
// Or for CLI: ensure args has at least one non-dash argument
var packages = args.Where(a => !a.StartsWith("-")).ToList();
if (packages.Count == 0)
{
    Console.Error.WriteLine("Usage: choco upgrade <package-name> [options]");
    Environment.Exit(1);
}

Type guard

public static bool HasValidPackageNames(ChocolateyConfiguration config)
{
    return !string.IsNullOrWhiteSpace(config?.PackageNames);
}

Try / catch

try
{
    upgradeCommand.Validate(configuration);
}
catch (ApplicationException ex) when (ex.Message.Contains("Package name is required"))
{
    logger.Error("No package specified. Usage: choco upgrade <package> [--force]");
    // Prompt user or return error
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13). Data as JSON: /api/errors/a80cd64905b2fbc2. Report an issue: GitHub.