golangci/golangci-lint · error
error getting working directory: %w
Error message
error getting working directory: %w
What it means
The PathRelativity processor constructor (NewPathRelativity) failed to determine the current working directory via fsutils.Getwd, which is required to compute relative paths in the output. The underlying OS error is wrapped and the runner aborts construction.
Source
Thrown at pkg/result/processors/path_relativity.go:25
"github.com/golangci/golangci-lint/v2/pkg/fsutils"
"github.com/golangci/golangci-lint/v2/pkg/logutils"
"github.com/golangci/golangci-lint/v2/pkg/result"
)
var _ Processor = (*PathRelativity)(nil)
// PathRelativity computes [result.Issue.RelativePath] and [result.Issue.WorkingDirectoryRelativePath],
// based on the base path.
type PathRelativity struct {
log logutils.Log
basePath string
workingDirectory string
}
func NewPathRelativity(log logutils.Log, basePath string) (*PathRelativity, error) {
wd, err := fsutils.Getwd()
if err != nil {
return nil, fmt.Errorf("error getting working directory: %w", err)
}
return &PathRelativity{
log: log.Child(logutils.DebugKeyPathRelativity),
basePath: basePath,
workingDirectory: wd,
}, nil
}
func (*PathRelativity) Name() string {
return "path_relativity"
}
func (p *PathRelativity) Process(issues []*result.Issue) ([]*result.Issue, error) {
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
newIssue := *issue
var err errorView on GitHub (pinned to ed7a235d2d)
Solutions
- cd to a valid existing directory before invoking golangci-lint
- Recreate the deleted working directory or re-clone/checkout the project
- Check filesystem permissions on the current directory
- Run the linter with an absolute project path and an explicit working directory
Example fix
# before (dir was deleted by a build script) /tmp/build-1234 $ golangci-lint run // after cd /path/to/project && golangci-lint run
Defensive patterns
Strategy: validation
Validate before calling
wd, err := os.Getwd()
if err != nil {
return fmt.Errorf("cannot start lint: %w", err)
}
if fi, err := os.Stat(wd); err != nil || !fi.IsDir() {
return fmt.Errorf("working directory invalid: %s", wd)
} Try / catch
pr, err := processors.NewPathRelativity(log, basePath)
if err != nil {
return fmt.Errorf("runner init failed: %w", err)
} Prevention
- Always cd into an existing project directory before linting
- Avoid deleting the directory a process is running from
- In CI, checkout and lint in the same stable path
- Verify cwd exists in wrapper scripts before invoking golangci-lint
When it happens
Trigger: Calling NewPathRelativity (indirectly via NewRunner) in a process whose working directory no longer exists (deleted directory, removed container path) or where os.Getwd fails due to permission issues.
Common situations: Running golangci-lint from a directory deleted and recreated by another process/scripts; CI steps cd'ing into ephemeral paths; sandboxed environments lacking permission on the cwd.
Related errors
- Can't get working dir: %s
- can't write heap profile: %w
- get base path: %w
- can't open file %s: %w
- the configuration contains invalid elements
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/40acdd48cd1d8047.
Report an issue: GitHub.