chocolatey/choco · error · ApplicationException

When using the '--source' option with the 'choco list' comma

Error message

When using the '--source' option with the 'choco list' command, only a named alternative source can be provided.

What it means

The list command is local-only; if --source is provided it must name an ALTERNATIVE source (windowsfeatures, ruby, cygwin, python), not a normal feed. Run() throws when config.ExplicitSources is set AND config.SourceType == SourceTypes.Normal, because listing a normal/nuget source is not what local 'choco list' does.

Source

Thrown at src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs:261

        public virtual bool MayRequireAdminAccess()
        {
            return false;
        }

        public virtual void DryRun(ChocolateyConfiguration configuration)
        {
            configuration.ListCommand.LocalOnly = true;

            _packageService.ListDryRun(configuration);
        }

        public virtual void Run(ChocolateyConfiguration config)
        {
            // Would have liked to have done this in the Validate method, but can't, since the SourceType
            // hasn't yet been set, since the sources have not yet been parsed.
            if (!string.IsNullOrWhiteSpace(config.ExplicitSources) && config.SourceType == SourceTypes.Normal)
            {
                throw new ApplicationException("When using the '--source' option with the 'choco list' command, only a named alternative source can be provided.");
            }

            config.ListCommand.LocalOnly = true;

            // note: you must leave the .ToList() here or else the method won't be evaluated!
            var packageResults = _packageService.List(config).ToList();

            // if there are no results, exit with a 2 if enhanced exit codes is enabled.
            if (config.Features.UseEnhancedExitCodes && packageResults.Count == 0 && Environment.ExitCode == 0)
            {
                Environment.ExitCode = 2;
            }
        }

#pragma warning disable IDE0022, IDE1006
        [Obsolete("This overload is deprecated and will be removed in v3.")]
        public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyConfiguration configuration)
            => ConfigureArgumentParser(optionSet, configuration);

View on GitHub (pinned to 0d5abdd10c)

Solutions

  1. To search a remote/normal feed use 'choco search -s <feed>'.
  2. To list from an alternative source use its name: 'choco list -s windowsfeatures'.
  3. Omit --source entirely for local installed packages.

Example fix

# before
choco list -s https://community.chocolatey.org/api/v2/

# after
choco search -s https://community.chocolatey.org/api/v2/
Defensive patterns

Strategy: validation

Validate before calling

// For local listing, do not pass a normal source; route remote queries to 'search'.
var alternativeSources = new[] { "windowsfeatures","windowsfeature","ruby","cygwin","python" };
if (!string.IsNullOrWhiteSpace(source) && !alternativeSources.Contains(source, StringComparer.OrdinalIgnoreCase))
{
    RunChoco($"search -s \"{source}\"");  // remote query
    return;
}
RunChoco("list");

Type guard

static bool IsAlternativeSource(string s) =>
    new[] { "windowsfeatures","windowsfeature","ruby","cygwin","python" }
        .Contains(s, StringComparer.OrdinalIgnoreCase);

Prevention

When it happens

Trigger: Running 'choco list -s https://community.chocolatey.org/api/v2/' (a normal source) or 'choco list --source=\some-folder'. The check lives in Run() because SourceType is not yet resolved during Validate().

Common situations: Assuming 'choco list -s <feed>' queries a remote feed (that's 'choco search'); passing a local folder as a normal source; mixing search semantics into list.

Related errors


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