{"record":{"id":"39019c1d8aa04f2f","repo":"git-ecosystem/git-credential-manager","slug":"not-a-valid-uri-url","errorCode":null,"errorMessage":"Not a valid URI: '{url}'","messagePattern":"Not a valid URI: '(.+?)'","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Core/ISessionManager.cs","lineNumber":34,"sourceCode":"        /// </summary>\n        /// <returns>True if the session can display a web browser, false otherwise.</returns>\n        bool IsWebBrowserAvailable { get; }\n\n        /// <summary>\n        /// Open the system web browser to the specified URL.\n        /// </summary>\n        /// <param name=\"uri\"><see cref=\"Uri\"/> to open the browser at.</param>\n        /// <exception cref=\"InvalidOperationException\">Thrown if <see cref=\"IsWebBrowserAvailable\"/> is false.</exception>\n        void OpenBrowser(Uri uri);\n    }\n\n    public static class SessionManagerExtensions\n    {\n        public static void OpenBrowser(this ISessionManager sm, string url)\n        {\n            if (!Uri.TryCreate(url, UriKind.Absolute, out Uri uri))\n            {\n                throw new ArgumentException($\"Not a valid URI: '{url}'\");\n            }\n\n            sm.OpenBrowser(uri);\n        }\n    }\n    \n    public abstract class SessionManager : ISessionManager\n    {\n        protected ITrace Trace { get; }\n        protected IEnvironment Environment { get; }\n        protected IFileSystem FileSystem { get; }\n\n        protected SessionManager(ITrace trace, IEnvironment env, IFileSystem fs)\n        {\n            EnsureArgument.NotNull(trace, nameof(trace));\n            EnsureArgument.NotNull(env, nameof(env));\n            EnsureArgument.NotNull(fs, nameof(fs));\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/ISessionManager.cs#L16-L52","documentation":"The SessionManagerExtensions.OpenBrowser(string) overload parses the URL with Uri.TryCreate(UriKind.Absolute) and throws ArgumentException if the string is not an absolute URI, before handing it to the underlying session manager. It guards against launching a browser with a malformed or relative URL.","triggerScenarios":"Calling sm.OpenBrowser(url) with a string that is not an absolute URI — empty string, relative path like \"/login\", missing scheme like \"example.com/auth\", or a URL with invalid characters.","commonSituations":"Building OAuth/browser authentication URLs with string concatenation that omits the https:// scheme, capturing a truncated URL from logs, or passing a null/empty value from configuration.","solutions":["Ensure the URL string includes an absolute scheme, e.g. prefix with \"https://\" if missing","Validate the URL with Uri.TryCreate(url, UriKind.Absolute, out _) before calling OpenBrowser","Check where the URL originates (config, server response) — fix the producer sending a malformed/empty URL","Use UriBuilder to construct the URL from host/path components instead of string concatenation"],"exampleFix":"// before\nsm.OpenBrowser($\"{host}/login/device\"); // host lacks scheme -> throws\n// after\nvar url = $\"https://{host}/login/device\";\nif (Uri.TryCreate(url, UriKind.Absolute, out var _))\n    sm.OpenBrowser(url);","handlingStrategy":"validation","validationCode":"if (!Uri.TryCreate(url, UriKind.Absolute, out var uri) ||\n    (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps))\n    throw new ArgumentException($\"Browser URL must be an absolute http(s) URI, got: '{url}'\");","typeGuard":"bool IsAbsoluteHttpUrl(string s) => Uri.TryCreate(s, UriKind.Absolute, out var u) &&\n    (u.Scheme == Uri.UriSchemeHttp || u.Scheme == Uri.UriSchemeHttps);","tryCatchPattern":"try\n{\n    sm.OpenBrowser(url);\n}\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Not a valid URI\"))\n{\n    logger.LogError(ex, \"Malformed browser URL: {Url}\", url);\n}","preventionTips":["Always include the scheme (https://) when building URLs for browser opening","Validate with Uri.TryCreate(UriKind.Absolute) before any browser launch","Prefer UriBuilder over string concatenation for constructing URLs"],"tags":["uri","browser","argument-validation","csharp"],"backgroundTag":"invalid-url-format","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}