{"record":{"id":"266a20b3f68d462a","repo":"golangci/golangci-lint","slug":"failed-to-get-goenv-w","errorCode":null,"errorMessage":"failed to get goenv: %w","messagePattern":"failed to get goenv: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/run.go","lineNumber":706,"sourceCode":"\t\treturn nil, fmt.Errorf(\"failed to JSON marshal config linter settings: %w\", err)\n\t}\n\n\tconfigData := bytes.NewBufferString(\"linters.settings=\")\n\tconfigData.Write(lintersSettingsBytes)\n\tconfigData.WriteString(\"\\nbuild-tags=%s\" + strings.Join(cfg.Run.BuildTags, \",\"))\n\n\th := sha256.New()\n\tif _, err := h.Write(configData.Bytes()); err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn h.Sum(nil), nil\n}\n\nfunc computeGoModSalt() (string, error) {\n\tvalues, err := goenv.Get(context.Background(), goenv.GOMOD)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get goenv: %w\", err)\n\t}\n\n\tgoModPath := filepath.Clean(values[goenv.GOMOD])\n\n\tdata, err := os.ReadFile(goModPath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to read go.mod: %w\", err)\n\t}\n\n\t// NOTE: the variable `goModPath` is not used here to ensure getting the same hash, independently of the location, for the same content.\n\tsum, err := dirhash.Hash1([]string{\"go.mod\"}, func(string) (io.ReadCloser, error) {\n\t\treturn io.NopCloser(bytes.NewReader(data)), nil\n\t})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to compute go.sum: %w\", err)\n\t}\n\n\treturn sum, nil","sourceCodeStart":688,"sourceCodeEnd":724,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/run.go#L688-L724","documentation":"computeGoModSalt reads the GOMOD environment value via the goenv package to hash go.mod for cache keys; a goenv.Get failure is wrapped as \"failed to get goenv\". goenv shells out to / inspects the local Go toolchain, so this indicates the Go environment could not be interrogated.","triggerScenarios":"goenv.Get(context.Background(), goenv.GOMOD) fails — typically the `go` binary is missing from PATH, or running `go env GOMOD` errors (broken Go installation, GOFLAGS/env problems, go unavailable in the sandbox).","commonSituations":"CI images without the Go toolchain installed (only the golangci-lint binary); restricted Docker images where the go binary was removed to shrink size; PATH not including /usr/local/go/bin in cron or systemd contexts.","solutions":["Ensure the `go` toolchain is installed and on PATH (`which go`, `go version`).","Run from within a Go module directory; the code only warns on missing go.mod, but goenv itself must still succeed.","In minimal Docker images, keep the go binary or run the lint stage in a full Go image (e.g. golang:1.x).","Fix corrupted Go installations (reinstall the toolchain) if `go env` itself errors.","Check inherited GOFLAGS/GO111MODULE values that could make `go env` fail."],"exampleFix":"// before (Dockerfile)\nFROM alpine\nCOPY golangci-lint /usr/bin/   # no go toolchain -> goenv fails\n// after\nFROM golang:1.22\nCOPY golangci-lint /usr/bin/","handlingStrategy":"validation","validationCode":"if _, err := exec.LookPath(\"go\"); err != nil {\n\treturn fmt.Errorf(\"go toolchain not on PATH; goenv (and cache salt) will fail\")\n}\nif err := exec.Command(\"go\", \"version\").Run(); err != nil {\n\treturn fmt.Errorf(\"go binary present but broken: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(); err != nil && strings.Contains(err.Error(), \"failed to get goenv\") {\n\tlog.Fatalf(\"ensure `go` is installed and on PATH: %v\", err)\n}","preventionTips":["Verify `go version` works in the same shell/CI step before linting.","Use Go-inclusive base images (golang:1.x) for lint stages.","Add /usr/local/go/bin to PATH in cron/systemd/non-interactive contexts.","Reinstall a corrupted toolchain if `go env` itself errors."],"tags":["goenv","cache","environment","ci","golangci-lint"],"backgroundTag":"go-toolchain-not-found","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}