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 error

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. cd to a valid existing directory before invoking golangci-lint
  2. Recreate the deleted working directory or re-clone/checkout the project
  3. Check filesystem permissions on the current directory
  4. 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

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


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