{"record":{"id":"2afa5c0a546a023f","repo":"golangci/golangci-lint","slug":"failed-to-remove-dir-s-w","errorCode":null,"errorMessage":"failed to remove dir %s: %w","messagePattern":"failed to remove dir (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/cache.go","lineNumber":60,"sourceCode":"\t\t\tArgs:              cobra.NoArgs,\n\t\t\tValidArgsFunction: cobra.NoFileCompletions,\n\t\t\tRunE:              c.executeStatus,\n\t\t},\n\t)\n\n\tc.cmd = cacheCmd\n\n\treturn c\n}\n\nfunc (*cacheCommand) executeClean(_ *cobra.Command, _ []string) error {\n\tcacheDir, err := cache.DefaultDir()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif err := os.RemoveAll(cacheDir); err != nil {\n\t\treturn fmt.Errorf(\"failed to remove dir %s: %w\", cacheDir, err)\n\t}\n\n\treturn nil\n}\n\nfunc (*cacheCommand) executeStatus(_ *cobra.Command, _ []string) error {\n\tcacheDir, err := cache.DefaultDir()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t_, _ = fmt.Fprintf(logutils.StdOut, \"Dir: %s\\n\", cacheDir)\n\n\tcacheSizeBytes, err := dirSizeBytes(cacheDir)\n\tif err == nil {\n\t\t_, _ = fmt.Fprintf(logutils.StdOut, \"Size: %s\\n\", fsutils.PrettifyBytesCount(cacheSizeBytes))\n\t}\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/cache.go#L42-L78","documentation":"The cache clean command (cacheCommand.executeClean) resolves the default cache directory with cache.DefaultDir(), then removes it recursively with os.RemoveAll. If RemoveAll fails, the error is wrapped as \"failed to remove dir %s: %w\" so the developer knows which directory could not be deleted.","triggerScenarios":"Running the cache clean subcommand when os.RemoveAll(cacheDir) cannot delete the cache directory or its contents.","commonSituations":"Permission denied (cache dir owned by root or another user, read-only filesystem); a file inside the cache is held open or locked by another running process; directory mounted (e.g. in a container volume) and cannot be unlinked; disk in a bad state.","solutions":["Check permissions on the reported cache directory (ls -ld) and fix ownership (chown) or run with sufficient privileges","Stop other instances of the tool that may hold files in the cache open, then retry","If the path is a read-only or mounted volume, unmount or point the cache elsewhere via its config/env override","Read the wrapped %w error (os.PathError) to see the exact failing path and errno (EACCES, EBUSY, EROFS)"],"exampleFix":"// before\n$ golangci-lint cache clean\n// failed to remove dir /root/.cache/golangci-lint: permission denied\n\n// after\n$ sudo chown -R $(whoami) /root/.cache/golangci-lint\n$ golangci-lint cache clean  # succeeds","handlingStrategy":"try-catch","validationCode":"cacheDir, err := cache.DefaultDir()\nif err != nil {\n    return err\n}\nif info, err := os.Stat(cacheDir); err != nil {\n    return fmt.Errorf(\"cache dir %s not accessible: %w\", cacheDir, err)\n} else if info.Mode().Perm()&0200 == 0 {\n    return fmt.Errorf(\"cache dir %s not writable by current user\", cacheDir)\n}","typeGuard":"var pathErr *os.PathError\nif errors.As(err, &pathErr) {\n    if errors.Is(pathErr.Err, fs.ErrPermission) { /* advise chown/sudo */ }\n    if errors.Is(pathErr.Err, syscall.EBUSY) { /* advise stopping other processes */ }\n}","tryCatchPattern":"if err := os.RemoveAll(cacheDir); err != nil {\n    var pe *os.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, fs.ErrPermission) {\n        return fmt.Errorf(\"insufficient permissions to remove %s: %w\", cacheDir, err)\n    }\n    return fmt.Errorf(\"failed to remove dir %s: %w\", cacheDir, err)\n}","preventionTips":["Run the tool as the same user that owns the cache directory","Avoid pointing the cache at mounted or read-only volumes","Stop parallel instances before cleaning the cache","Check that the parent directory grants write permission (removal requires write on the parent)"],"tags":["filesystem","permissions","cache"],"backgroundTag":"remove-directory-permission-denied","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}