{"record":{"id":"4fb4ce4aad8cc416","repo":"chocolatey/choco","slug":"the-0-source-does-not-support-searching-for-pa","errorCode":null,"errorMessage":"The '{0}' source does not support searching for packages","messagePattern":"The '(.+?)' source does not support searching for packages","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs","lineNumber":281,"sourceCode":"            IEnumerable<PackageResult> results;\r\n\r\n            if (config.ListCommand.LocalOnly && !config.SourceType.IsEqualTo(SourceTypes.Normal))\r\n            {\r\n                results = PerformSourceRunnerFunction<IListSourceRunner, IEnumerable<PackageResult>>(config, runner => runner.List(config));\r\n            }\r\n            else if (config.SourceType.IsEqualTo(SourceTypes.Normal))\r\n            {\r\n                results = _nugetService.List(config).OrEmpty();\r\n            }\r\n            else\r\n            {\r\n                results = PerformSourceRunnerFunction<ISearchableSourceRunner, IEnumerable<PackageResult>>(config, runner => runner.Search(config));\r\n            }\r\n\r\n            if (results is null)\r\n            {\r\n                var message = config.ListCommand.LocalOnly ? \"The '{0}' source does not support listing of packages\".FormatWith(config.SourceType) : \"The '{0}' source does not support searching for packages\".FormatWith(config.SourceType);\r\n                throw new NotSupportedException(message);\r\n            }\r\n\r\n            foreach (PackageResult package in results)\r\n            {\r\n                if (config.SourceType.IsEqualTo(SourceTypes.Normal))\r\n                {\r\n                    if (!config.ListCommand.IncludeRegistryPrograms)\r\n                    {\r\n                        yield return package;\r\n                    }\r\n\r\n                    if (config.ListCommand.LocalOnly && config.ListCommand.IncludeRegistryPrograms && package.PackageMetadata != null)\r\n                    {\r\n                        packages.Add(package);\r\n                    }\r\n                }\r\n            }\r\n\r","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs#L263-L299","documentation":"Thrown as a NotSupportedException when a non-normal source type (e.g. cygwin, python, ruby, windowsfeatures) fails to return search or list results. PerformSourceRunnerFunction resolves an ISearchableSourceRunner (or IListSourceRunner for LocalOnly) for the configured SourceType; if no registered runner implements that interface the function returns default (null), and the subsequent null-check fires this exception. The exact message variant depends on config.ListCommand.LocalOnly — 'listing' vs 'searching'.","triggerScenarios":"Calling List() on ChocolateyPackageService with config.SourceType set to an alternative source (not 'normal') when either (a) no alternative source runner implementing ISearchableSourceRunner/IListSourceRunner is registered in the DI container, or (b) the resolved runner exists but its Search/List method returns null. The LocalOnly flag selects the runner interface and the error message variant.","commonSituations":"A user or automation script runs 'choco search --source-type python' or 'choco list --local-only --source-type windowsfeatures' against a source type whose runner does not implement the required search/list interface. Also occurs when a custom alternative source runner is registered but missing the ISearchableSourceRunner interface implementation.","solutions":["Verify the --source-type value is valid and that its corresponding runner implements ISearchableSourceRunner or IListSourceRunner.","If using a normal NuGet/Chocolatey feed, ensure config.SourceType equals SourceTypes.Normal so the _nugetService.List path is taken instead of the runner path.","For custom alternative source runners, implement the ISearchableSourceRunner interface (Search method) or IListSourceRunner (List method) on the runner class and register it in the container.","If listing locally installed packages, set config.ListCommand.LocalOnly = true and ensure the runner implements IListSourceRunner."],"exampleFix":"// before: runner missing the interface\npublic class MyCustomRunner : IAlternativeSourceRunner\n{\n    // no Search or List implementation\n}\n\n// after: implement the required interface\npublic class MyCustomRunner : IAlternativeSourceRunner, ISearchableSourceRunner\n{\n    public IEnumerable<PackageResult> Search(ChocolateyConfiguration config)\n    {\n        // return results, never null\n        return Enumerable.Empty<PackageResult>();\n    }\n}","handlingStrategy":"validation","validationCode":"// Before calling List, verify the source type supports the operation\nvar supportedSourceTypes = new[] { SourceTypes.Normal, SourceTypes.Cygwin, SourceTypes.Python, SourceTypes.WindowsFeatures };\nif (!supportedSourceTypes.Contains(config.SourceType, StringComparer.OrdinalIgnoreCase))\n{\n    throw new InvalidOperationException($\"Unsupported source type: {config.SourceType}\");\n}\nif (!config.SourceType.IsEqualTo(SourceTypes.Normal))\n{\n    var runners = _containerResolver.ResolveAll<ISearchableSourceRunner>();\n    if (!runners.Any(r => r.SourceType.IsEqualTo(config.SourceType)))\n    {\n        // warn user before the API call fails\n        throw new InvalidOperationException($\"Source type '{config.SourceType}' has no runner implementing ISearchableSourceRunner.\");\n    }\n}","typeGuard":"public static bool SourceTypeSupportsSearch(string sourceType, IEnumerable<IAlternativeSourceRunner> registeredRunners)\n{\n    if (sourceType.IsEqualTo(SourceTypes.Normal)) return true;\n    return registeredRunners.OfType<ISearchableSourceRunner>().Any(r => r.SourceType.IsEqualTo(sourceType));\n}","tryCatchPattern":"try\n{\n    var results = _packageService.List(config);\n    foreach (var pkg in results) { /* process */ }\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"does not support\"))\n{\n    // Surface a user-friendly message about unsupported source type\n    logger.Error($\"Source type '{config.SourceType}' cannot search. Use --source-type=normal or install the appropriate runner.\");\n}","preventionTips":["Always verify config.SourceType is set to a known SourceTypes constant before calling List/Search.","Register custom alternative source runners in the DI container with the appropriate interfaces (ISearchableSourceRunner, IListSourceRunner).","Test source type operations with dry-run commands before production use."],"tags":["source-runner","alternative-source","search","notsupported","chocolatey"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}