golangci/golangci-lint · error

get base path: %w

Error message

get base path: %w

What it means

NewRunnerOptions resolves the base path used for formatter path matching via fsutils.GetBasePath, honoring run.relative-path-mode. If that resolution fails (bad mode value or filesystem error), the error is wrapped with this prefix and construction aborts before any formatting runs.

Source

Thrown at pkg/goformat/runner.go:226

	return c.exitCode
}

type RunnerOptions struct {
	basePath  string
	patterns  []*regexp.Regexp
	generated string
	diff      bool
	colors    bool
	stdin     bool

	warnUnused          bool
	excludedPathCounter map[*regexp.Regexp]int
}

func NewRunnerOptions(cfg *config.Config, diff, diffColored, stdin bool) (RunnerOptions, error) {
	basePath, err := fsutils.GetBasePath(context.Background(), cfg.Run.RelativePathMode, cfg.GetConfigDir())
	if err != nil {
		return RunnerOptions{}, fmt.Errorf("get base path: %w", err)
	}

	// Required to be consistent with `RunnerOptions.MatchAnyPattern`.
	absBasePath, err := filepath.Abs(basePath)
	if err != nil {
		return RunnerOptions{}, err
	}

	opts := RunnerOptions{
		basePath:            absBasePath,
		generated:           cfg.Formatters.Exclusions.Generated,
		diff:                diff || diffColored,
		colors:              diffColored,
		stdin:               stdin,
		excludedPathCounter: make(map[*regexp.Regexp]int),
		warnUnused:          cfg.Formatters.Exclusions.WarnUnused,
	}

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Set run.relative-path-mode to a valid value (e.g. `gomod`, `git-root`, `cfg`, or `cwd`) in .golangci.yml
  2. Run golangci-lint from an existing directory (cd into the repo root)
  3. Check that the config dir and symlinks resolve correctly (ls -l the paths)
  4. Upgrade golangci-lint if your configured mode value should be supported

Example fix

# before
run:
  relative-path-mode: relitive
# after
run:
  relative-path-mode: gomod
Defensive patterns

Strategy: validation

Validate before calling

# validate config before running
run:
  relative-path-mode: gomod   # one of: gomod, git-root, cfg, cwd

Try / catch

// wrap construction and fail fast with config context
ro, err := NewRunnerOptions(cfg, diff, diffColored, stdin)
if err != nil {
    return fmt.Errorf("runner options invalid, check run.relative-path-mode: %w", err)
}

Prevention

When it happens

Trigger: Calling NewRunnerOptions with a config whose run.relative-path-mode is invalid, or whose config dir/working dir cannot be resolved (e.g. deleted cwd, symlink issues).

Common situations: Typo in `.golangci.yml` under run.relative-path-mode; running the binary from a deleted working directory; symlinked config directories that don't resolve.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/eac028022b6d326a. Report an issue: GitHub.