{"record":{"id":"1952f9c38890c918","repo":"golangci/golangci-lint","slug":"get-go-mod-path-w","errorCode":null,"errorMessage":"get go.mod path: %w","messagePattern":"get go\\.mod path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/fsutils/basepath.go","lineNumber":43,"sourceCode":"func AllRelativePathModes() []string {\n\treturn []string{RelativePathModeGoMod, RelativePathModeGitRoot, RelativePathModeCfg, RelativePathModeWd}\n}\n\nfunc GetBasePath(ctx context.Context, mode, cfgDir string) (string, error) {\n\tmode = cmp.Or(mode, RelativePathModeCfg)\n\n\tswitch mode {\n\tcase RelativePathModeCfg:\n\t\tif cfgDir == \"\" {\n\t\t\treturn GetBasePath(ctx, RelativePathModeWd, cfgDir)\n\t\t}\n\n\t\treturn cfgDir, nil\n\n\tcase RelativePathModeGoMod:\n\t\tgoMod, err := goenv.GetOne(ctx, goenv.GOMOD)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"get go.mod path: %w\", err)\n\t\t}\n\n\t\treturn filepath.Dir(goMod), nil\n\n\tcase RelativePathModeGitRoot:\n\t\troot, err := gitRoot(ctx)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"get git root: %w\", err)\n\t\t}\n\n\t\treturn root, nil\n\n\tcase RelativePathModeWd:\n\t\twd, err := Getwd()\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"get wd: %w\", err)\n\t\t}\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/fsutils/basepath.go#L25-L61","documentation":"GetBasePath returns this wrapped error when the configured relative path mode is RelativePathModeGoMod and goenv.GetOne(ctx, goenv.GOMOD) fails to resolve the go.mod file path. The underlying cause (module resolution failure, missing toolchain, bad GOFLAGS, etc.) is preserved via %w. golangci-lint needs the go.mod directory to compute relative paths for reports.","triggerScenarios":"Calling golangci-lint with run.relative-path-mode: gomod in a directory where `go env GOMOD` fails — e.g. no Go toolchain installed, or the go command errors resolving the module.","commonSituations":"Running golangci-lint outside a Go module with gomod mode forced; broken Go installation; CI images without the go binary; GOPATH/GOFLAGS env misconfiguration.","solutions":["Fix the underlying `go env GOMOD` failure (inspect the wrapped error) — ensure the go toolchain is installed and on PATH","Run golangci-lint inside a valid Go module directory that contains a go.mod","Switch run.relative-path-mode to 'git-root' or 'wd' if go.mod resolution is not required"],"exampleFix":"// before (config)\nrun:\n  relative-path-mode: gomod\n// after\nrun:\n  relative-path-mode: wd","handlingStrategy":"try-catch","validationCode":"// verify go.mod resolvable before running\ncmd := exec.Command(\"go\", \"env\", \"GOMOD\")\nif out, err := cmd.Output(); err != nil || strings.TrimSpace(string(out)) == \"/dev/null\" {\n  return fmt.Errorf(\"no resolvable go.mod: %v %s\", err, out)\n}","typeGuard":null,"tryCatchPattern":"basePath, err := fsutils.GetBasePath(ctx, mode)\nvar wrapped error\nif errors.As(err, &wrapped) {\n  log.Fatalf(\"get base path failed: %v\", err) // inspect wrapped go env GOMOD cause\n}","preventionTips":["Ensure the go toolchain is installed and on PATH","Run the linter inside a module directory containing go.mod","Choose git-root or wd relative-path-mode when go.mod is not needed"],"tags":["go-modules","filesystem","path-resolution"],"backgroundTag":"gomod-resolution-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}