golang/go · error

cannot parse output of GOAUTH command %s: %v

Error message

cannot parse output of GOAUTH command %s: %v

What it means

Emitted from runAuthCommand when the custom GOAUTH command ran successfully (exit 0) but parseUserAuth rejected its stdout. parseUserAuth expects a repeating structure of: one or more absolute URL lines, a blank line, one or more `Name: value` header lines, a blank line (see `go help goauth`). Empty output is allowed and yields no credentials.

Source

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

	}
	cmd, err := buildCommand(command)
	if err != nil {
		return nil, err
	}
	if url != "" {
		cmd.Args = append(cmd.Args, url)
	}
	cmd.Stderr = new(strings.Builder)
	if res != nil && writeResponseToStdin(cmd, res) != nil {
		return nil, fmt.Errorf("could not run command %s: %v\n%s", command, err, cmd.Stderr)
	}
	out, err := cmd.Output()
	if err != nil {
		return nil, fmt.Errorf("could not run command %s: %v\n%s", command, err, cmd.Stderr)
	}
	credentials, err := parseUserAuth(string(out))
	if err != nil {
		return nil, fmt.Errorf("cannot parse output of GOAUTH command %s: %v", command, err)
	}
	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")

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Read `go help goauth` and emit exactly: URL line(s), blank line, `Name: value` header line(s), blank line.
  2. Send any diagnostic/log output to stderr, not stdout.
  3. Use LF (\n) line endings, not CRLF.
  4. Return empty output (no credentials) rather than malformed text when there is nothing to provide.
Defensive patterns

Strategy: validation

Validate before calling

// Lint GOAUTH command output against the documented format before use.
func validateAuthOutput(s string) error {
    _, err := parseUserAuth(s) // reuse the parser in a test
    return err
}

Prevention

When it happens

Trigger: The command prints non-empty output that does not follow the URLs-blank-headers-blank format: an unparseable URL, a header line missing `: `, a missing terminating blank line, or a totally different shape (JSON, free text).

Common situations: Command prints a login banner, debug text, or JSON to stdout instead of the documented format; CRLF line endings; missing trailing blank line; header without a space after the colon.

Related errors


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