golangci/golangci-lint · error
can't get relative path for path %s and root %s: %w
Error message
can't get relative path for path %s and root %s: %w
What it means
Wrapping error in ShortestRelPath: filepath.Rel(wd, absPath) failed after resolving the path against the working directory. Rel rarely fails — typically the wd could not be made relative to the target (e.g. mismatched roots on Windows or a wd that no longer exists).
Source
Thrown at pkg/fsutils/fsutils.go:97
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)
}
relPath, err := filepath.Rel(wd, absPath)
if err != nil {
return "", fmt.Errorf("can't get relative path for path %s and root %s: %w",
absPath, wd, err)
}
return relPath, nil
}
View on GitHub (pinned to ed7a235d2d)
Solutions
- Verify the working directory and target path share a valid root
- Check that the wd exists and is a directory
- Inspect the wrapped error for the exact Rel failure reason
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at pkg/fsutils/fsutils.go:97 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/c29f58952a498e5b.
Report an issue: GitHub.