{"record":{"id":"668fd5b21819d279","repo":"charmbracelet/glow","slug":"unable-to-parse-url-w","errorCode":null,"errorMessage":"unable to parse url: %w","messagePattern":"unable to parse url: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"url.go","lineNumber":48,"sourceCode":"\tswitch {\n\tcase strings.HasPrefix(path, protoGithub):\n\t\tif u := githubReadmeURL(path); u != nil {\n\t\t\treturn readmeURL(u.String())\n\t\t}\n\t\treturn nil, nil\n\tcase strings.HasPrefix(path, protoGitlab):\n\t\tif u := gitlabReadmeURL(path); u != nil {\n\t\t\treturn readmeURL(u.String())\n\t\t}\n\t\treturn nil, nil\n\t}\n\n\tif !strings.HasPrefix(path, protoHTTPS) {\n\t\tpath = protoHTTPS + path\n\t}\n\tu, err := url.Parse(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to parse url: %w\", err)\n\t}\n\n\tswitch {\n\tcase u.Hostname() == githubURL.Hostname():\n\t\treturn findGitHubREADME(u)\n\tcase u.Hostname() == gitlabURL.Hostname():\n\t\treturn findGitLabREADME(u)\n\t}\n\n\treturn nil, nil\n}\n\nfunc githubReadmeURL(path string) *url.URL {\n\tpath = strings.TrimPrefix(path, protoGithub)\n\tparts := strings.Split(path, \"/\")\n\tif len(parts) != 2 {\n\t\t// custom hostnames are not supported yet\n\t\treturn nil","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/charmbracelet/glow/blob/e3970c813d93da1ea84edfca90c289d9afb82242/url.go#L30-L66","documentation":"Thrown by readmeURL (url.go:43-49) when interpreting a CLI argument as a GitHub/GitLab README location: if the argument lacks an https:// prefix one is prepended, and then url.Parse must succeed. url.Parse only errors on structurally invalid URLs — control characters or spaces in the wrong places, invalid percent-escapes like %zz, or an invalid port. Note glow's caller (sourceFromArg, main.go:81-85) deliberately swallows this error and falls through to local-file handling, so in the shipped binary the visible effect is usually 'argument treated as a file path' rather than this message.","triggerScenarios":"`glow example.com/50%off` — invalid URL escape \"%of\"; an unquoted argument containing a space; a pasted URL with leading/trailing whitespace or an embedded newline; a malformed port segment such as `example.com:8o0x`.","commonSituations":"Unquoted shell arguments; URLs copied with invisible whitespace or newlines; literal percent signs in paths that were never percent-encoded; scripts passing unsanitized strings as the glow argument.","solutions":["Quote the argument and strip stray whitespace: `glow \"github.com/charmbracelet/glow\"`.","Percent-encode literal percent signs: `%` → `%25` (e.g. `example.com/50%25off`).","Fix or drop the malformed port/scheme portion of the URL.","In code, pre-screen with url.ParseRequestURI or the repo's own isURL() (url.go:83) before calling readmeURL."],"exampleFix":"# before\n$ glow example.com/50%off\n# unable to parse url: parse \"https://example.com/50%off\": invalid URL escape \"%of\"\n\n# after\n$ glow \"example.com/50%25off\"","handlingStrategy":"validation","validationCode":"func looksLikeURL(path string) bool {\n\tif strings.ContainsAny(path, \" \\t\\r\\n\") {\n\t\treturn false\n\t}\n\t_, err := url.Parse(path)\n\treturn err == nil\n}\n\n// only attempt README resolution when the screen passes:\nif looksLikeURL(arg) {\n\tsrc, err := readmeURL(arg)\n\t_ = err // caller already falls through to file handling\n}","typeGuard":"func isParseURLError(err error) bool {\n\tvar ue *url.Error\n\treturn errors.As(err, &ue) && ue.Op == \"parse\"\n}","tryCatchPattern":"src, err := readmeURL(arg)\nif err != nil {\n\t// not a usable URL: mirror main.go's behavior and continue\n\t// with local-file handling instead of aborting\n\tlog.Debug(\"argument is not a parseable URL\", \"arg\", arg, \"error\", err)\n}","preventionTips":["Quote glow arguments in shell scripts and trim whitespace from pasted URLs.","Percent-encode literal percent signs (%25) and non-ASCII path segments.","Remember readmeURL only resolves github.com and gitlab.com hosts; other hosts return nil, nil.","Pre-screen arguments with url.ParseRequestURI when building tools on top of glow."],"tags":["url","parsing","validation","cli","shell"],"backgroundTag":null,"analyzedSha":"e3970c813d93da1ea84edfca90c289d9afb82242","analyzedAt":"2026-08-15T22:50:54.304Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}