golangci/golangci-lint · error

can't get working directory: %w

Error message

can't get working directory: %w

What it means

Wrapping error in ShortestRelPath: when no working directory is supplied, Getwd() is called and its failure (os-level failure or unresolvable symlinks on the wd) is re-wrapped with this prefix. The relative-path computation cannot proceed without a wd.

Source

Thrown at pkg/fsutils/fsutils.go:75

	r, ok := evalSymlinkCache.Load(path)
	if ok {
		er := r.(evalSymlinkRes)
		return er.path, er.err
	}

	var er evalSymlinkRes
	er.path, er.err = evalSymlinks(path)
	evalSymlinkCache.Store(path, er)

	return er.path, er.err
}

func ShortestRelPath(path, wd string) (string, error) {
	if wd == "" { // get it if user don't have cached working dir
		var err error
		wd, err = Getwd()
		if err != nil {
			return "", fmt.Errorf("can't get working directory: %w", err)
		}
	}

	evaluatedPath, err := EvalSymlinks(path)
	if err != nil {
		return "", fmt.Errorf("can't eval symlinks for path %s: %w", path, err)
	}
	path = evaluatedPath

	// make path absolute and then relative to be able to fix this case:
	// we are in `/test` dir, we want to normalize `../test`, and have file `file.go` in this dir;
	// it must have normalized path `file.go`, not `../test/file.go`,
	var absPath string
	if filepath.IsAbs(path) {
		absPath = path
	} else {
		absPath = filepath.Join(wd, path)
	}

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Ensure the process working directory is valid
  2. Pass an explicit working directory where the API allows
  3. Resolve broken symlinks on the working directory
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at pkg/fsutils/fsutils.go:75 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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