{"record":{"id":"892afba75b693e24","repo":"golangci/golangci-lint","slug":"failed-to-read-go-mod-w","errorCode":null,"errorMessage":"failed to read go.mod: %w","messagePattern":"failed to read go\\.mod: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/run.go","lineNumber":713,"sourceCode":"\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\n}\n","sourceCodeStart":695,"sourceCodeEnd":726,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/run.go#L695-L726","documentation":"computeGoModSalt reads the go.mod file (located via goenv.GOMOD) to compute a dirhash that salts lint-result caching. If os.ReadFile fails, this error wraps the underlying OS error and aborts hash-salt initialization during `golangci-lint run`/cache setup.","triggerScenarios":"`golangci-lint run` with cache hashing enabled where the go.mod path reported by `go env GOMOD` does not exist or is unreadable: running outside a Go module, GOFLAGS/env pointing elsewhere, deleted go.mod, or permission-restricted go.mod.","commonSituations":"Running golangci-lint in a directory without go.mod (GOPATH mode or non-module dir); CI checkout missing go.mod; restrictive file permissions; GOMOD env var overridden in containers.","solutions":["Run golangci-lint from a directory inside a valid Go module that contains go.mod","Verify `go env GOMOD` points at an existing go.mod file","Restore go.mod (e.g. `git checkout -- go.mod`) if it was deleted","Fix file permissions on go.mod so the lint process can read it"],"exampleFix":"// before (broken CI)\nrun: golangci-lint run ./...\n// after\nrun: |\n  test -f go.mod || go mod init\ngolangci-lint run ./...","handlingStrategy":"validation","validationCode":"gomod := os.Getenv(\"GOMOD\")\nif gomod == \"\" || gomod == os.DevNull {\n\treturn fmt.Errorf(\"not inside a Go module: GOMOD is empty\")\n}\nif _, err := os.Stat(gomod); err != nil {\n\treturn fmt.Errorf(\"go.mod unreadable at %s: %w\", gomod, err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run golangci-lint from within a module directory containing go.mod","Check `go env GOMOD` in CI before linting","Pin CI checkouts to include go.mod (verify with `test -f go.mod`)","Avoid overwriting GOMOD-related env vars in containers"],"tags":["go","golangci-lint","cache","go-mod"],"backgroundTag":"go-mod-not-found","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}