{"record":{"id":"fb84533ee9fb532a","repo":"golang/go","slug":"v-w","errorCode":null,"errorMessage":"%v: %w","messagePattern":"%v: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"misc/go_android_exec/main.go","lineNumber":375,"sourceCode":"\t}\n\treturn nil\n}\n\n// adbCopyGoroot clears deviceRoot for previous versions of GOROOT, GOPATH\n// and temporary data. Then, it copies relevant parts of GOROOT to the device,\n// including the go tool built for android.\n// A lock file ensures this only happens once, even with concurrent exec\n// wrappers.\nfunc adbCopyGoroot() error {\n\tgoTool, err := goTool()\n\tif err != nil {\n\t\treturn err\n\t}\n\tcmd := exec.Command(goTool, \"version\")\n\tcmd.Stderr = os.Stderr\n\tout, err := cmd.Output()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%v: %w\", cmd, err)\n\t}\n\tgoVersion := string(out)\n\n\t// Also known by cmd/dist. The bootstrap command deletes the file.\n\tstatPath := filepath.Join(os.TempDir(), \"go_android_exec-adb-sync-status\")\n\tstat, err := os.OpenFile(statPath, os.O_CREATE|os.O_RDWR, 0666)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer stat.Close()\n\t// Serialize check and copying.\n\tif err := syscall.Flock(int(stat.Fd()), syscall.LOCK_EX); err != nil {\n\t\treturn err\n\t}\n\ts, err := io.ReadAll(stat)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/misc/go_android_exec/main.go#L357-L393","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run `<goTool> version` manually and confirm it prints a version string.","Ensure GOROOT is set and $GOROOT/bin/go is executable: `go version`.","If the host toolchain is broken, reinstall Go or rebuild from source.","Inspect the wrapped error (errors.Is/Unwrap) for the real exec failure."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Confirm the host Go toolchain works before go_android_exec sync.\nfunc goToolWorks(goTool string) error {\n    c := exec.Command(goTool, \"version\")\n    c.Stderr = os.Stderr\n    out, err := c.Output()\n    if err != nil {\n        return fmt.Errorf(\"%s version: %w\", goTool, err)\n    }\n    if !strings.HasPrefix(string(out), \"go version\") {\n        return errors.New(\"unexpected go version output\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `go version` before invoking go_android_exec.","Ensure $GOROOT/bin/go is executable and on PATH.","Unwrap the %w error to see the real exec cause."],"tags":["android","go-toolchain","exec","goroot-sync"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}