golang/go · error

could not run command %s: %v %s

Error message

could not run command %s: %v
%s

What it means

Emitted from runAuthCommand in the branch `if res != nil && writeResponseToStdin(cmd, res) != nil`. This branch is effectively dead code in the current source: writeResponseToStdin (userauth.go:117-125) always returns nil, and the `err` referenced in the format string is the already-checked buildCommand error (guaranteed nil at this point). If a future refactor makes writeResponseToStdin return a real error, this message would print `<nil>` for %v. End users cannot trigger it today.

Source

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

// runAuthCommand executes a user provided GOAUTH command, parses its output, and
// returns a mapping of prefix → http.Header.
// It uses the client to verify the credential and passes the status to the
// command's stdin.
// res is used for the GOAUTH command's stdin.
func runAuthCommand(command string, url string, res *http.Response) (map[string]http.Header, error) {
	if command == "" {
		panic("GOAUTH invoked an empty authenticator command:" + command) // This should be caught earlier.
	}
	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) {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. No end-user action; this is dead code today.
  2. If maintaining: capture the real error from writeResponseToStdin and use it instead of the stale `err` variable.

Example fix

// before
if res != nil && writeResponseToStdin(cmd, res) != nil {
    return nil, fmt.Errorf("could not run command %s: %v\n%s", command, err, cmd.Stderr)
}
// after
if res != nil {
    if werr := writeResponseToStdin(cmd, res); werr != nil {
        return nil, fmt.Errorf("could not write response to command %s: %v\n%s", command, werr, cmd.Stderr)
    }
}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Not reachable in the current codebase — writeResponseToStdin never returns a non-nil error, so the condition is always false.

Common situations: N/A; latent bug. Would only surface after a refactor that adds a failure mode to writeResponseToStdin without updating this branch.

Related errors


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