chocolatey/choco · error · ApplicationException

When specifying the subcommand '{0}', you must also specify

Error message

When specifying the subcommand '{0}', you must also specify --value by option or position.

What it means

Validate() requires a value when setting a config entry. If ConfigCommand.Command == Set and configuration.ConfigCommand.ConfigValue is blank, it throws, naming the subcommand. A set needs both a target name and the value to write.

Source

Thrown at src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs:102

            {
                configuration.ConfigCommand.Name = unparsedArguments[1];
            }
            if (string.IsNullOrWhiteSpace(configuration.ConfigCommand.ConfigValue) && unparsedArguments.Count >= 3)
            {
                configuration.ConfigCommand.ConfigValue = unparsedArguments[2];
            }
        }

        public virtual void Validate(ChocolateyConfiguration configuration)
        {
            if (configuration.ConfigCommand.Command != ConfigCommandType.List && string.IsNullOrWhiteSpace(configuration.ConfigCommand.Name))
            {
                throw new ApplicationException("When specifying the subcommand '{0}', you must also specify --name by option or position.".FormatWith(configuration.ConfigCommand.Command.ToStringSafe().ToLower()));
            }

            if (configuration.ConfigCommand.Command == ConfigCommandType.Set && string.IsNullOrWhiteSpace(configuration.ConfigCommand.ConfigValue))
            {
                throw new ApplicationException("When specifying the subcommand '{0}', you must also specify --value by option or position.".FormatWith(configuration.ConfigCommand.Command.ToStringSafe().ToLower()));
            }
        }

        public virtual void HelpMessage(ChocolateyConfiguration configuration)
        {
            this.Log().Info(ChocolateyLoggers.Important, "Config Command");
            this.Log().Info(@"
Chocolatey will allow you to interact with the configuration file settings.
");

            "chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");
            "chocolatey".Log().Info(@"
    choco config [list]|get|set|unset [<options/switches>]
");

            "chocolatey".Log().Info(ChocolateyLoggers.Important, "Examples");
            "chocolatey".Log().Info(@"
    choco config

View on GitHub (pinned to 0d5abdd10c)

Solutions

  1. Add --value <value> (or a positional value): 'choco config set --name cacheLocation --value C:\cache'.
  2. To clear a setting, use the appropriate unset/empty handling rather than omitting the value.
  3. Verify the value is not whitespace-only.

Example fix

# before
choco config set --name cacheLocation

# after
choco config set --name cacheLocation --value C:\choco\cache
Defensive patterns

Strategy: validation

Validate before calling

// 'set' requires a value.
if (configVerb == "set" && string.IsNullOrWhiteSpace(value))
{
    throw new InvalidOperationException("config set requires --value");
}

Prevention

When it happens

Trigger: Running 'choco config set --name <setting>' (or 'set name') with no --value and no positional value token.

Common situations: Supplying the name but omitting the value; passing the value on the wrong side of the name; quoting that collapses the value to empty.

Related errors


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