{"record":{"id":"9cc83c6ef3d9fb03","repo":"golangci/golangci-lint","slug":"w","errorCode":null,"errorMessage":"%w","messagePattern":"%w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/goutil/env.go","lineNumber":34,"sourceCode":"type Env struct {\n\tvars map[string]string\n\tlog  logutils.Log\n}\n\nfunc NewEnv(log logutils.Log) *Env {\n\treturn &Env{\n\t\tvars: map[string]string{},\n\t\tlog:  log,\n\t}\n}\n\nfunc (e Env) Discover(ctx context.Context) error {\n\tstartedAt := time.Now()\n\n\tvar err error\n\te.vars, err = goenv.Get(ctx, goenv.GOCACHE, goenv.GOROOT)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%w\", err)\n\t}\n\n\te.log.Infof(\"Read go env for %s: %#v\", time.Since(startedAt), e.vars)\n\n\treturn nil\n}\n\nfunc (e Env) Get(k EnvKey) string {\n\tenvValue := os.Getenv(string(k))\n\tif envValue != \"\" {\n\t\treturn envValue\n\t}\n\n\treturn e.vars[string(k)]\n}\n","sourceCodeStart":16,"sourceCodeEnd":50,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/goutil/env.go#L16-L50","documentation":"Env.Discover reads GOCACHE and GOROOT by invoking the go toolchain via goenv.Get (grignotin/goenv). This error is returned when that call fails: the go binary could not be executed, its output could not be parsed, or the context was canceled. The raw error is re-wrapped verbatim with fmt.Errorf(\"%w\", err), so the root cause appears directly in the message.","triggerScenarios":"Calling Discover (directly or via runAndPrint during a golangci-lint run) when the go binary is missing from PATH, the Go version is too old or its `go env` output format is unexpected, GOCACHE/GOROOT point to invalid locations, `go env` exits non-zero, or ctx is canceled before goenv.Get completes.","commonSituations":"Running golangci-lint in a Docker/CI image without the Go toolchain; GOENV/GOFLAGS misconfiguration breaking `go env`; GOCACHE pointing to a non-writable path; a broken Go installation after an upgrade.","solutions":["Verify `go env GOCACHE GOROOT` succeeds in the same shell/environment where golangci-lint runs.","Install the Go toolchain and ensure it is on PATH inside the container/CI job running the linter.","Check GOENV, GOFLAGS, GOPROXY and GOCACHE environment variables for invalid or conflicting values.","Run with verbose logging to surface the wrapped root cause if the message is opaque.","As a last resort, reinstall a supported Go version and clear GOCACHE (`go clean -cache`)."],"exampleFix":"# before (CI image without a toolchain)\nimage: golangci/golangci-lint:latest  # no go installed, `go env` fails\n# after\nimage: golang:1.23\nscript:\n  - go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest\n  - golangci-lint run","handlingStrategy":"try-catch","validationCode":"// Ensure the go toolchain is usable before invoking the linter\nfunc checkGoToolchain() error {\n\tctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)\n\tdefer cancel()\n\tif out, err := exec.CommandContext(ctx, \"go\", \"env\", \"GOCACHE\", \"GOROOT\").Output(); err != nil {\n\t\treturn fmt.Errorf(\"go toolchain unavailable: %w\", err)\n\t} else {\n\t\t_ = out\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"env := goutil.NewEnv(log)\nif err := env.Discover(ctx); err != nil {\n\tif errors.Is(err, context.DeadlineExceeded) {\n\t\treturn fmt.Errorf(\"go env timed out; check GOFLAGS/proxy settings: %w\", err)\n\t}\n\treturn fmt.Errorf(\"cannot read go env (is Go installed and on PATH?): %w\", err)\n}","preventionTips":["Install the Go toolchain in every container/CI image that runs golangci-lint.","Verify `go env GOCACHE GOROOT` succeeds in the same environment before linting.","Keep GOCACHE writable and GOENV/GOFLAGS free of conflicting values.","Set reasonable context timeouts for go env discovery."],"tags":["golang","environment","go-env","toolchain"],"backgroundTag":"go-env-discovery-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}