golang/go · error
could not parse URL %s: %v
Error message
could not parse URL %s: %v
What it means
Raised inside parseUserAuth for each non-blank URL line: the line must pass url.ParseRequestURI, which requires an absolute URI with a scheme. If parsing fails, this error names the offending line and wraps the parse error.
Source
Thrown at src/cmd/go/internal/auth/userauth.go:70
// See the expected format in 'go help goauth'.
func parseUserAuth(data string) (map[string]http.Header, error) {
credentials := make(map[string]http.Header)
for data != "" {
var line string
var ok bool
var urls []string
// Parse URLS first.
for {
line, data, ok = strings.Cut(data, "\n")
if !ok {
return nil, fmt.Errorf("invalid format: missing empty line after URLs")
}
if line == "" {
break
}
u, err := url.ParseRequestURI(line)
if err != nil {
return nil, fmt.Errorf("could not parse URL %s: %v", line, err)
}
urls = append(urls, u.String())
}
// Parse Headers second.
header := make(http.Header)
for {
line, data, ok = strings.Cut(data, "\n")
if !ok {
return nil, fmt.Errorf("invalid format: missing empty line after headers")
}
if line == "" {
break
}
name, value, ok := strings.Cut(line, ": ")
value = strings.TrimSpace(value)
if !ok || !validHeaderFieldName(name) || !validHeaderFieldValue(value) {
return nil, fmt.Errorf("invalid format: invalid header line")
}View on GitHub (pinned to b6b368adc5)
Solutions
- Always include the scheme and host: `https://example.com/path`.
- Trim trailing whitespace/CR from each URL line.
- Percent-encode any spaces or non-ASCII bytes in the path/query.
- Test lines with Go's `url.ParseRequestURI` before emitting them.
Example fix
// before example.com // after https://example.com
Defensive patterns
Strategy: validation
Validate before calling
// Validate each URL line before emitting it.
if _, err := url.ParseRequestURI(line); err != nil {
return fmt.Errorf("invalid URL line %q: %w", line, err)
} Prevention
- Always include scheme and host: `https://example.com/path`.
- Trim trailing whitespace/CR.
- Percent-encode spaces and non-ASCII bytes in the path/query.
When it happens
Trigger: A URL line that is not an absolute request URI: a bare hostname (`example.com`), a path without scheme (`/foo`), a line containing spaces or control characters, or invalid percent-encoding.
Common situations: Writing `example.com` instead of `https://example.com`; trailing whitespace or a carriage return; non-ASCII characters; unencoded spaces in the path.
Related errors
- cannot parse output of GOAUTH command %s: %v
- invalid format: missing empty line after URLs
- invalid format: missing empty line after headers
- invalid format: invalid header line
- 'git credential fill' failed for url=%s, could not parse url
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/97f835eeaa523f68.
Report an issue: GitHub.