golangci/golangci-lint · error
unknown relative path mode: %s
Error message
unknown relative path mode: %s
What it means
GetBasePath returns this error when the given relative path mode does not match any known case in its switch. It means an unrecognized RelativePathMode string reached the resolver, typically from config validation gaps or programmatic construction with an invalid mode. Valid modes are the fsutils RelativePathMode constants (gomod, git-root, wd, absolute-style).
Source
Thrown at pkg/fsutils/basepath.go:65
case RelativePathModeGitRoot:
root, err := gitRoot(ctx)
if err != nil {
return "", fmt.Errorf("get git root: %w", err)
}
return root, nil
case RelativePathModeWd:
wd, err := Getwd()
if err != nil {
return "", fmt.Errorf("get wd: %w", err)
}
return wd, nil
default:
return "", fmt.Errorf("unknown relative path mode: %s", mode)
}
}
func gitRoot(ctx context.Context) (string, error) {
cmd := exec.CommandContext(ctx, "git", "rev-parse", "--show-toplevel")
out, err := cmd.Output()
if err != nil {
return "", err
}
return string(bytes.TrimSpace(out)), nil
}
View on GitHub (pinned to ed7a235d2d)
Solutions
- Use a mode from fsutils.AllRelativePathModes() / the RelativePathMode constants instead of a hand-written string
- Run Run.Validate() before using the config so invalid modes are rejected earlier with a clearer message
- Check the version you are using: rename obsolete mode strings to their current names
Example fix
// before mode := "gomod-file" // after mode := fsutils.RelativePathModeGoMod
Defensive patterns
Strategy: validation
Validate before calling
mode := cfg.Run.RelativePathMode
if mode != "" && !slices.Contains(fsutils.AllRelativePathModes(), mode) {
return fmt.Errorf("unknown relative path mode %q; use %v", mode, fsutils.AllRelativePathModes())
} Prevention
- Only pass fsutils.RelativePathMode* constants, never raw strings
- Call Run.Validate() before using config programmatically
- Align mode names with the pinned golangci-lint version when upgrading
When it happens
Trigger: Calling GetBasePath with a mode string not among the fsutils relative path modes — e.g. after typos in config that bypass validation, or constructing fsutils options programmatically with a wrong constant/string.
Common situations: Custom tooling built on golangci-lint's internal config passing hand-written mode strings; version skew where a mode name was renamed; config generated by scripts with wrong values.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- the configuration contains invalid elements
- unsupported configuration format
- root field 'version' is required
- no plugins defined
- field 'module' is required
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/cd482f8929c835a5.
Report an issue: GitHub.