{"record":{"id":"9bc48b9fe744b33a","repo":"chocolatey/choco","slug":"source-0-is-unable-to-be-parsed","errorCode":null,"errorMessage":"Source '{0}' is unable to be parsed","messagePattern":"Source '(.+?)' is unable to be parsed","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/nuget/NugetCommon.cs","lineNumber":260,"sourceCode":"                    // Conversion to absolute paths is handled by clients, not by the libraries as per\r\n                    // https://github.com/NuGet/NuGet.Client/pull/3783\r\n                    if (nugetSource.TrySourceAsUri is null)\r\n                    {\r\n                        string fullsource;\r\n                        try\r\n                        {\r\n                            fullsource = filesystem.GetFullPath(source);\r\n                        }\r\n                        catch\r\n                        {\r\n                            // If an invalid source was passed in, we don't care here, pass it along\r\n                            fullsource = source;\r\n                        }\r\n                        nugetSource = new PackageSource(fullsource);\r\n\r\n                        if (!nugetSource.IsLocal)\r\n                        {\r\n                            throw new ApplicationException(\"Source '{0}' is unable to be parsed\".FormatWith(source));\r\n                        }\r\n\r\n                        \"chocolatey\".Log().Debug(\"Updating Source path from {0} to {1}\".FormatWith(source, fullsource));\r\n                        updatedSources.AppendFormat(\"{0};\", fullsource);\r\n                    }\r\n                    else\r\n                    {\r\n                        updatedSources.AppendFormat(\"{0};\", source);\r\n                    }\r\n\r\n                    nugetSource.ClientCertificates = sourceClientCertificates;\r\n                    var repo = Repository.Factory.GetCoreV3(nugetSource);\r\n\r\n                    if (nugetSource.IsHttp || nugetSource.IsHttps)\r\n                    {\r\n#pragma warning disable RS0030 // Do not used banned APIs\r\n                        var httpSourceResource = repo.GetResource<HttpSourceResource>();\r\n#pragma warning restore RS0030 // Do not used banned APIs\r","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs#L242-L278","documentation":"Thrown by NugetCommon.GetRepositoryResources when a source string cannot be parsed as either an HTTP(S) URI or a local filesystem path. The code first checks if the source resolves to a valid URI (TrySourceAsUri is not null); if not, it attempts to convert to an absolute filesystem path via filesystem.GetFullPath. If the result is still not recognized as a local path (IsLocal is false), the source is considered unparseable.","triggerScenarios":"Passing a malformed source URL (e.g. 'htp://feed.example.com' with a typo in the protocol). Passing a source that is neither a valid URI nor a valid filesystem path (e.g. 'feed:||broken'). Passing an empty or whitespace-only source after the initial empty-source filtering. Passing a UNC path or environment-variable-containing path that GetFullPath cannot resolve.","commonSituations":"Typo in the --source URL ('https' misspelled). Source string contains unresolved environment variables or ~ that aren't expanded. Configuration file has a corrupted source entry. Network proxy or redirect URL that doesn't parse as a standard URI. Source passed with extra quotes or whitespace characters.","solutions":["Verify the source URL is a valid HTTP(S) URI: 'choco install pkg --source=https://valid.url/feed'","Verify the local source path exists and is accessible: 'choco install pkg --source=C:\\packages'","Remove typos in the protocol (must be http:// or https://)","Check for hidden characters, quotes, or whitespace in the source string","If using environment variables in the path, ensure they resolve before passing"],"exampleFix":"// before\nchoco install mypackage --source=htps://community.chocolatey.org/api/v2/\n\n// after\nchoco install mypackage --source=https://community.chocolatey.org/api/v2/","handlingStrategy":"validation","validationCode":"// Validate source before passing to NugetCommon\nbool IsValidSource(string source)\n{\n    if (Uri.TryCreate(source, UriKind.Absolute, out var uri))\n        return uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps;\n    try\n    {\n        var full = Path.GetFullPath(source);\n        return Directory.Exists(full) || File.Exists(full);\n    }\n    catch { return false; }\n}\n\nif (!IsValidSource(configSource))\n{\n    Console.Error.WriteLine($\"Source '{configSource}' is not a valid HTTP(S) URL or local path.\");\n}","typeGuard":"public static bool IsValidSourceUrl(string source)\n{\n    if (string.IsNullOrWhiteSpace(source)) return false;\n    if (Uri.TryCreate(source, UriKind.Absolute, out var uri))\n        return uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps;\n    try { Path.GetFullPath(source); return true; }\n    catch { return false; }\n}","tryCatchPattern":"try\n{\n    var repos = NugetCommon.GetRepositoryResources(config, logger, filesystem, cacheContext);\n}\ncatch (ApplicationException ex) when (ex.Message.Contains(\"unable to be parsed\"))\n{\n    logger.Error($\"Source could not be parsed. Verify it is a valid HTTP(S) URL or local path.\");\n}","preventionTips":["Verify source URLs start with http:// or https:// before using them","For local paths, confirm the directory or file exists","Remove extra whitespace, quotes, or control characters from source strings","Expand environment variables in paths before passing them as sources","Use 'choco source list' to verify configured sources are valid"],"tags":["source","nuget","uri-parsing","filesystem","configuration"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}