chocolatey/choco · error · ApplicationException

When specifying the subcommand 'add', you must also specify

Error message

When specifying the subcommand 'add', you must also specify --source.

What it means

Thrown by ChocolateySourceCommand.Validate when the subcommand is 'add' and configuration.Sources is null or empty. Adding a source requires both a name (--name) and a source URL (--source). This specific check guards the missing --source case, which is separate from the --name check above it.

Source

Thrown at src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs:115

                    this.Log().Warn("Unknown command {0}. Setting to list.".FormatWith(unparsedCommand));
                }

                command = SourceCommandType.List;
            }

            configuration.SourceCommand.Command = command;
        }

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

            if (configuration.SourceCommand.Command == SourceCommandType.Add && string.IsNullOrWhiteSpace(configuration.Sources))
            {
                throw new ApplicationException("When specifying the subcommand 'add', you must also specify --source.");
            }

            if (!string.IsNullOrWhiteSpace(configuration.SourceCommand.Username) && string.IsNullOrWhiteSpace(configuration.SourceCommand.Password))
            {
                this.Log().Debug(ChocolateyLoggers.LogFileOnly, "Username '{0}' provided. Asking for password.".FormatWith(configuration.SourceCommand.Username));
                System.Console.Write("User name '{0}' provided. Password: ".FormatWith(configuration.SourceCommand.Username));
                configuration.SourceCommand.Password = InteractivePrompt.GetPassword(configuration.PromptForConfirmation);
            }
        }

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

            "chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");

View on GitHub (pinned to 0d5abdd10c)

Solutions

  1. Add the --source flag with the feed URL: 'choco source add --name=myfeed --source="https://my.feed/nuget"'.
  2. Ensure the --source value is properly quoted, especially if it contains special characters.
  3. Verify both --name and --source are present before running.

Example fix

// before
choco source add --name="myfeed"
// after
choco source add --name="myfeed" --source="https://my.feed/nuget"
Defensive patterns

Strategy: validation

Validate before calling

// For 'add', ensure --source is provided
if (sourceSubcommand == "add" && string.IsNullOrWhiteSpace(sourceUrl))
{
    Console.Error.WriteLine("choco source add requires both --name and --source.");
}

Prevention

When it happens

Trigger: Running 'choco source add --name=myfeed' without specifying --source=<url>. The condition: SourceCommand.Command == Add AND configuration.Sources is empty.

Common situations: User provides only a name for the new source and forgets the URL. Argument typo where --source is misspelled or misquoted so it is not parsed.

Related errors


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