{"record":{"id":"9f2033b83efe7ac1","repo":"chocolatey/choco","slug":"when-using-the-source-option-with-the-choco-l","errorCode":null,"errorMessage":"When using the '--source' option with the 'choco list' command, only a named alternative source can be provided.","messagePattern":"When using the '--source' option with the 'choco list' command, only a named alternative source can be provided\\.","errorType":"validation","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs","lineNumber":261,"sourceCode":"        public virtual bool MayRequireAdminAccess()\r\n        {\r\n            return false;\r\n        }\r\n\r\n        public virtual void DryRun(ChocolateyConfiguration configuration)\r\n        {\r\n            configuration.ListCommand.LocalOnly = true;\r\n\r\n            _packageService.ListDryRun(configuration);\r\n        }\r\n\r\n        public virtual void Run(ChocolateyConfiguration config)\r\n        {\r\n            // Would have liked to have done this in the Validate method, but can't, since the SourceType\r\n            // hasn't yet been set, since the sources have not yet been parsed.\r\n            if (!string.IsNullOrWhiteSpace(config.ExplicitSources) && config.SourceType == SourceTypes.Normal)\r\n            {\r\n                throw new ApplicationException(\"When using the '--source' option with the 'choco list' command, only a named alternative source can be provided.\");\r\n            }\r\n\r\n            config.ListCommand.LocalOnly = true;\r\n\r\n            // note: you must leave the .ToList() here or else the method won't be evaluated!\r\n            var packageResults = _packageService.List(config).ToList();\r\n\r\n            // if there are no results, exit with a 2 if enhanced exit codes is enabled.\r\n            if (config.Features.UseEnhancedExitCodes && packageResults.Count == 0 && Environment.ExitCode == 0)\r\n            {\r\n                Environment.ExitCode = 2;\r\n            }\r\n        }\r\n\r\n#pragma warning disable IDE0022, IDE1006\r\n        [Obsolete(\"This overload is deprecated and will be removed in v3.\")]\r\n        public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyConfiguration configuration)\r\n            => ConfigureArgumentParser(optionSet, configuration);\r","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs#L243-L279","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","solutions":["To search a remote/normal feed use 'choco search -s <feed>'.","To list from an alternative source use its name: 'choco list -s windowsfeatures'.","Omit --source entirely for local installed packages."],"exampleFix":"# before\nchoco list -s https://community.chocolatey.org/api/v2/\n\n# after\nchoco search -s https://community.chocolatey.org/api/v2/","handlingStrategy":"validation","validationCode":"// For local listing, do not pass a normal source; route remote queries to 'search'.\nvar alternativeSources = new[] { \"windowsfeatures\",\"windowsfeature\",\"ruby\",\"cygwin\",\"python\" };\nif (!string.IsNullOrWhiteSpace(source) && !alternativeSources.Contains(source, StringComparer.OrdinalIgnoreCase))\n{\n    RunChoco($\"search -s \\\"{source}\\\"\");  // remote query\n    return;\n}\nRunChoco(\"list\");","typeGuard":"static bool IsAlternativeSource(string s) =>\n    new[] { \"windowsfeatures\",\"windowsfeature\",\"ruby\",\"cygwin\",\"python\" }\n        .Contains(s, StringComparer.OrdinalIgnoreCase);","tryCatchPattern":null,"preventionTips":["Use 'choco search -s <feed>' for remote/normal feed queries; reserve 'choco list' for local packages.","Only pass alternative source names (windowsfeatures, ruby, cygwin, python) to 'choco list -s'.","Omit --source entirely for a plain local list."],"tags":["list","source","alternative-source","search-vs-list"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}