{"record":{"id":"40acdd48cd1d8047","repo":"golangci/golangci-lint","slug":"error-getting-working-directory-w","errorCode":null,"errorMessage":"error getting working directory: %w","messagePattern":"error getting working directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/result/processors/path_relativity.go","lineNumber":25,"sourceCode":"\t\"github.com/golangci/golangci-lint/v2/pkg/fsutils\"\n\t\"github.com/golangci/golangci-lint/v2/pkg/logutils\"\n\t\"github.com/golangci/golangci-lint/v2/pkg/result\"\n)\n\nvar _ Processor = (*PathRelativity)(nil)\n\n// PathRelativity computes [result.Issue.RelativePath] and [result.Issue.WorkingDirectoryRelativePath],\n// based on the base path.\ntype PathRelativity struct {\n\tlog              logutils.Log\n\tbasePath         string\n\tworkingDirectory string\n}\n\nfunc NewPathRelativity(log logutils.Log, basePath string) (*PathRelativity, error) {\n\twd, err := fsutils.Getwd()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting working directory: %w\", err)\n\t}\n\n\treturn &PathRelativity{\n\t\tlog:              log.Child(logutils.DebugKeyPathRelativity),\n\t\tbasePath:         basePath,\n\t\tworkingDirectory: wd,\n\t}, nil\n}\n\nfunc (*PathRelativity) Name() string {\n\treturn \"path_relativity\"\n}\n\nfunc (p *PathRelativity) Process(issues []*result.Issue) ([]*result.Issue, error) {\n\treturn transformIssues(issues, func(issue *result.Issue) *result.Issue {\n\t\tnewIssue := *issue\n\n\t\tvar err error","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/result/processors/path_relativity.go#L7-L43","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before (dir was deleted by a build script)\n/tmp/build-1234 $ golangci-lint run\n// after\ncd /path/to/project && golangci-lint run","handlingStrategy":"validation","validationCode":"wd, err := os.Getwd()\nif err != nil {\n    return fmt.Errorf(\"cannot start lint: %w\", err)\n}\nif fi, err := os.Stat(wd); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"working directory invalid: %s\", wd)\n}","typeGuard":null,"tryCatchPattern":"pr, err := processors.NewPathRelativity(log, basePath)\nif err != nil {\n    return fmt.Errorf(\"runner init failed: %w\", err)\n}","preventionTips":["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"],"tags":["golangci-lint","working-directory","filesystem"],"backgroundTag":"working-directory-unavailable","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}