{"record":{"id":"2b7dcae5dcd18165","repo":"golangci/golangci-lint","slug":"reading-go-mod-file-w","errorCode":null,"errorMessage":"reading go.mod file: %w","messagePattern":"reading go\\.mod file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/config.go","lineNumber":168,"sourceCode":"func parseGoVersion(v string) string {\n\traw := strings.TrimPrefix(v, \"go\")\n\n\t// prerelease version (ex: go1.24rc1)\n\tidx := strings.IndexFunc(raw, func(r rune) bool {\n\t\treturn (r < '0' || r > '9') && r != '.'\n\t})\n\n\tif idx != -1 {\n\t\traw = raw[:idx]\n\t}\n\n\treturn raw\n}\n\nfunc parseGoMod(goMod string) (*modfile.File, error) {\n\traw, err := os.ReadFile(filepath.Clean(goMod))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"reading go.mod file: %w\", err)\n\t}\n\n\treturn modfile.Parse(\"go.mod\", raw, nil)\n}\n\nfunc detectGoModFallback(ctx context.Context) string {\n\tinfo, err := gomod.GetModuleInfo(ctx)\n\tif err != nil {\n\t\treturn \"\"\n\t}\n\n\twd, err := os.Getwd()\n\tif err != nil {\n\t\treturn \"\"\n\t}\n\n\tslices.SortFunc(info, func(a, b gomod.ModInfo) int {\n\t\treturn cmp.Compare(len(b.Path), len(a.Path))","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/config/config.go#L150-L186","documentation":"parseGoMod reads the go.mod file from disk to detect the Go version; if os.ReadFile fails it wraps the OS error with this message. This happens when go.mod is missing, unreadable, or the resolved path is wrong.","triggerScenarios":"Calling detectGoVersionFromGoMod with a path to a go.mod that does not exist, has restrictive permissions, or whose directory was deleted; bad cfgDir/working directory resolution pointing at the wrong path.","commonSituations":"Running golangci-lint in a module subdirectory without go.mod at the resolved path; CI checking out only partial repo; go.mod deleted or renamed; permission issues in containers.","solutions":["Ensure go.mod exists at the expected location (repository/module root)","Run golangci-lint from the module directory or fix the config directory/path settings","Fix file permissions so the linting user can read go.mod","Set the Go version explicitly in config (run.go) instead of relying on go.mod detection"],"exampleFix":"// before\ndetectGoVersionFromGoMod(ctx) // fails: no go.mod in cwd\n// after\n// run from module root, or ensure go.mod exists:\n// $ cd /path/to/module && golangci-lint run","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(\"go.mod\"); err != nil {\n\treturn fmt.Errorf(\"go.mod missing in %s: %w\", dir, err)\n}","typeGuard":null,"tryCatchPattern":"if _, err := detectGoVersionFromGoMod(ctx); err != nil {\n\tvar pe *fs.PathError\n\tif errors.As(err, &pe) { log.Printf(\"go.mod unreadable: %s\", pe.Path) }\n}","preventionTips":["Run golangci-lint from the module root","Ensure CI checks out the full repository including go.mod","Pin the Go version in config instead of relying on go.mod detection"],"tags":["golangci-lint","go-mod","file-io"],"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"}