golang/go · error
invalid format: missing empty line after URLs
Error message
invalid format: missing empty line after URLs
What it means
Raised inside parseUserAuth while collecting URL lines. The loop cuts input on `\n`; if strings.Cut returns ok=false (no more newlines) before an empty line terminates the URL list, the URL section was never closed and parsing aborts with this message.
Source
Thrown at src/cmd/go/internal/auth/userauth.go:63
return credentials, nil
}
// parseUserAuth parses the output from a GOAUTH command and
// returns a mapping of prefix → http.Header without the leading "https://"
// or an error if the data does not follow the expected format.
// Returns a nil error and an empty map if the data is empty.
// 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 == "" {View on GitHub (pinned to b6b368adc5)
Solutions
- Terminate every URL list with a blank line.
- End each credential block with `\n\n` (URLs, blank, headers, blank).
- Validate output locally before relying on it: pipe the command's stdout through a parser in a test.
Example fix
// malformed: no blank line after URL https://example.com Authorization: Bearer x // fixed https://example.com Authorization: Bearer x
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the URL list is blank-line-terminated.
func endsURLBlock(s string) bool {
return strings.Contains(s, "\n\n")
} Prevention
- Terminate each URL list with a blank line.
- End every credential block with `\n\n`.
- Unit-test the command's stdout against parseUserAuth.
When it happens
Trigger: The GOAUTH command output contains URL lines but no terminating blank line, or the input ends mid-URL-list without a final newline.
Common situations: Output written without a trailing `\n\n`; the command emits URLs only and forgets the blank separator; a single block missing its closing empty line.
Related errors
- cannot parse output of GOAUTH command %s: %v
- invalid format: missing empty line after headers
- could not parse URL %s: %v
- 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/c50479d07e2e3765.
Report an issue: GitHub.