golang/go · error

invalid format: missing empty line after headers

Error message

invalid format: missing empty line after headers

What it means

Raised inside parseUserAuth while collecting header lines that follow the URL list and its blank line. The loop cuts on `\n`; if strings.Cut returns ok=false (no more newlines) before a blank line terminates the header section, parsing aborts.

Source

Thrown at src/cmd/go/internal/auth/userauth.go:79

			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")
			}
			header.Add(name, value)
		}
		maps.Copy(credentials, mapHeadersToPrefixes(urls, header))
	}
	return credentials, nil
}

// mapHeadersToPrefixes returns a mapping of prefix → http.Header without
// the leading "https://".

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Terminate every header block with a blank line.
  2. End output with `\n\n` after the last header.
  3. Validate the full structure (URLs, blank, headers, blank) in a unit test before shipping the command.
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the header block is blank-line-terminated.
func endsHeaderBlock(s string) bool {
    return strings.HasSuffix(strings.TrimRight(s, "\n"), "") && strings.Count(s, "\n\n") >= 1
}

Prevention

When it happens

Trigger: The GOAUTH command output has header lines with no following blank line, or the input ends mid-header-section without a final newline.

Common situations: Missing trailing `\n\n` after the header block; output truncated; a single credential block whose closing blank line was omitted.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/69d6684f680d64cf. Report an issue: GitHub.