{"record":{"id":"a83f8033272cd52c","repo":"abiosoft/colima","slug":"error-during-prune-w","errorCode":null,"errorMessage":"error during prune: %w","messagePattern":"error during prune: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/prune.go","lineNumber":42,"sourceCode":"\tUse:   \"prune\",\n\tShort: \"prune cached downloaded assets\",\n\tLong:  `Prune cached downloaded assets`,\n\tArgs:  cobra.MaximumNArgs(1),\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tcolimaCacheDir := config.CacheDir()\n\t\tlimaCacheDir := filepath.Join(filepath.Dir(colimaCacheDir), \"lima\")\n\t\tif !pruneCmdArgs.force {\n\t\t\tmsg := \"'\" + colimaCacheDir + \"' will be emptied, are you sure\"\n\t\t\tif pruneCmdArgs.all {\n\t\t\t\tmsg = \"'\" + colimaCacheDir + \"' and '\" + limaCacheDir + \"' will be emptied, are you sure\"\n\t\t\t}\n\t\t\tif y := cli.Prompt(msg); !y {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\t\tlogrus.Info(\"Pruning \", strconv.Quote(config.CacheDir()))\n\t\tif err := os.RemoveAll(config.CacheDir()); err != nil {\n\t\t\treturn fmt.Errorf(\"error during prune: %w\", err)\n\t\t}\n\n\t\tif pruneCmdArgs.all {\n\t\t\tcmd := limautil.Limactl(\"prune\")\n\t\t\tif err := cmd.Run(); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error during Lima prune: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\treturn nil\n\t},\n}\n\nfunc init() {\n\troot.Cmd().AddCommand(pruneCmd)\n\n\tpruneCmd.Flags().BoolVarP(&pruneCmdArgs.force, \"force\", \"f\", false, \"do not prompt for yes/no\")\n\tpruneCmd.Flags().BoolVarP(&pruneCmdArgs.all, \"all\", \"a\", false, \"include Lima assets\")","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/cmd/prune.go#L24-L60","documentation":"`colima prune` empties the colima cache directory (config.CacheDir(), logged just before) with os.RemoveAll. This error wraps a removal failure — overwhelmingly a permission problem: cache entries created by root because colima was previously run under sudo, files held open by a running VM, or a read-only cache location. Partial removal is possible: RemoveAll deletes what it can before failing.","triggerScenarios":"Cache dir contains root-owned files from earlier `sudo colima` runs while pruning as a regular user; a running colima instance holds files open in the cache; cache dir on a read-only or external volume; an interrupted earlier prune left odd permissions behind.","commonSituations":"Mixed sudo/non-sudo colima usage over time; pruning while `colima start` is in progress; macOS privacy permissions denying access to the cache parent directory.","solutions":["Check ownership of the logged cache dir (ls -la <cachedir>) and chown it back: `sudo chown -R $(id -un):staff <cachedir>`, then re-run `colima prune --force`","Or remove directly with elevated rights: `sudo rm -rf <cachedir>` — the path is printed in the 'Pruning ...' log line","Stop colima first (`colima stop`) so nothing in the cache is held open, then prune"],"exampleFix":"# before\n$ colima prune --force\nerror: error during prune: ... permission denied\n\n# after\n$ sudo chown -R \"$USER\":staff ~/.cache/colima   # or the logged CacheDir\n$ colima prune --force","handlingStrategy":"try-catch","validationCode":"// verify you can actually write/delete in the cache dir before pruning\nfunc removable(dir string) bool {\n    f, err := os.CreateTemp(dir, \".probe-*\")\n    if err != nil {\n        return false // not writable -> prune will fail\n    }\n    return os.Remove(f.Name()) == nil\n}","typeGuard":null,"tryCatchPattern":"if err := pruneCmd.Execute(); err != nil {\n    if errors.Is(err, fs.ErrPermission) {\n        // escalate deliberately: sudo chown -R $USER <cachedir> (or sudo rm -rf), then retry\n    }\n}","preventionTips":["Never alternate sudo and non-sudo colima runs — mixed ownership is the top cause","Stop colima (`colima stop`) before pruning so no process holds cache files open","Fix ownership of the cache dir (chown -R) as soon as you notice root-owned entries"],"tags":["colima","cache","filesystem","permissions","prune"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}