{"record":{"id":"4f94fb049965c252","repo":"golang/go","slug":"cannot-run-go-list-v-s","errorCode":null,"errorMessage":"cannot run go list: %v\n%s","messagePattern":"cannot run go list: (.+?)\n(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/cover/func.go","lineNumber":208,"sourceCode":"\t\tif _, ok := pkgs[pkg]; !ok {\n\t\t\tpkgs[pkg] = nil\n\t\t\tlist = append(list, pkg)\n\t\t}\n\t}\n\n\tif len(list) == 0 {\n\t\treturn pkgs, nil\n\t}\n\n\t// Note: usually run as \"go tool cover\" in which case $GOROOT is set,\n\t// in which case runtime.GOROOT() does exactly what we want.\n\tgoTool := filepath.Join(runtime.GOROOT(), \"bin/go\")\n\tcmd := exec.Command(goTool, append([]string{\"list\", \"-e\", \"-json\"}, list...)...)\n\tvar stderr bytes.Buffer\n\tcmd.Stderr = &stderr\n\tstdout, err := cmd.Output()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot run go list: %v\\n%s\", err, stderr.Bytes())\n\t}\n\tdec := json.NewDecoder(bytes.NewReader(stdout))\n\tfor {\n\t\tvar pkg Pkg\n\t\terr := dec.Decode(&pkg)\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"decoding go list json: %v\", err)\n\t\t}\n\t\tpkgs[pkg.ImportPath] = &pkg\n\t}\n\treturn pkgs, nil\n}\n\n// findFile finds the location of the named file in GOROOT, GOPATH etc.\nfunc findFile(pkgs map[string]*Pkg, file string) (string, error) {","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/cover/func.go#L190-L226","documentation":"Thrown by 'go tool cover' (func.go) when invoking `go list -e -json <pkgs>` fails (non-zero exit / exec error). The cover tool runs the go binary at $GOROOT/bin/go to resolve package metadata for source-file lookup during -func/-html report generation. The error wraps both the exec error and the command's stderr output.","triggerScenarios":"`go tool cover -func=profile.out` or `-html=profile.out` where the spawned `go list` fails: corrupt GOROOT, missing go binary, network/module download failure for a package referenced in the profile, or `go list` itself errors on a broken module.","commonSituations":"GOROOT unset or pointing at a deleted install. Profile referencing packages from a module that can no longer be resolved (deleted cache, GOPROXY issues, private module auth). Broken go.mod/go.sum. go binary not executable.","solutions":["Ensure GOROOT is correct and $GOROOT/bin/go exists and runs (`go env GOROOT`)","Run the equivalent `go list -e -json <pkg>` manually to see the real error from stderr","Fix module resolution: `go mod tidy`, GOPROXY/GOPRIVATE settings, or restore the module cache","Re-run `go test -coverprofile` to regenerate a fresh profile against the current module set"],"exampleFix":"# diagnose\nGOROOT=/bad go tool cover -func=c.out  # fails\n# fix\ngo env -w GOROOT=$(go env GOROOT)  # or reinstall Go\ngo list -e -json $(awk '{print $1}' c.out | cut -d: -f1 | xargs -n1 dirname | sort -u)","handlingStrategy":"validation","validationCode":"# Pre-flight: ensure go binary exists and go list works\nif [ ! -x \"$(go env GOROOT)/bin/go\" ]; then echo \"missing go binary\" >&2; exit 2; fi\ngo list -e -json ./... >/dev/null || { echo \"go list failed\" >&2; exit 2; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin GOROOT and verify the go binary before generating reports","Run `go mod tidy` and fix module errors before coverage reporting"],"tags":["go-toolchain","cover","subprocess","go-list","module-resolution"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}