golang/go · error

%v: %w

Error message

%v: %w

What it means

Returned by adbCopyGoroot (main.go:375) when `exec(<goTool>, 'version').Output()` fails. The wrapper needs the local Go toolchain version before syncing GOROOT to the device; if the host `go` command cannot run or exits non-zero, this wraps the error with %w (preserving the underlying cause).

Source

Thrown at misc/go_android_exec/main.go:375

	}
	return nil
}

// adbCopyGoroot clears deviceRoot for previous versions of GOROOT, GOPATH
// and temporary data. Then, it copies relevant parts of GOROOT to the device,
// including the go tool built for android.
// A lock file ensures this only happens once, even with concurrent exec
// wrappers.
func adbCopyGoroot() error {
	goTool, err := goTool()
	if err != nil {
		return err
	}
	cmd := exec.Command(goTool, "version")
	cmd.Stderr = os.Stderr
	out, err := cmd.Output()
	if err != nil {
		return fmt.Errorf("%v: %w", cmd, err)
	}
	goVersion := string(out)

	// Also known by cmd/dist. The bootstrap command deletes the file.
	statPath := filepath.Join(os.TempDir(), "go_android_exec-adb-sync-status")
	stat, err := os.OpenFile(statPath, os.O_CREATE|os.O_RDWR, 0666)
	if err != nil {
		return err
	}
	defer stat.Close()
	// Serialize check and copying.
	if err := syscall.Flock(int(stat.Fd()), syscall.LOCK_EX); err != nil {
		return err
	}
	s, err := io.ReadAll(stat)
	if err != nil {
		return err
	}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Run `<goTool> version` manually and confirm it prints a version string.
  2. Ensure GOROOT is set and $GOROOT/bin/go is executable: `go version`.
  3. If the host toolchain is broken, reinstall Go or rebuild from source.
  4. Inspect the wrapped error (errors.Is/Unwrap) for the real exec failure.
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the host Go toolchain works before go_android_exec sync.
func goToolWorks(goTool string) error {
    c := exec.Command(goTool, "version")
    c.Stderr = os.Stderr
    out, err := c.Output()
    if err != nil {
        return fmt.Errorf("%s version: %w", goTool, err)
    }
    if !strings.HasPrefix(string(out), "go version") {
        return errors.New("unexpected go version output")
    }
    return nil
}

Prevention

When it happens

Trigger: go_android_exec invokes the Go tool found via goTool() to print its version, and that subprocess fails: the go binary is missing/exec-bitted wrong, crashes, or the host toolchain is broken. The %v shows the command, %w the exec error.

Common situations: GOROOT/bin/go not on PATH or not executable; cross-compiled Go toolchain not built for the host; GOEXPERIMENT/Go install corruption; running go_android_exec outside a valid GOROOT setup.

Related errors


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