abiosoft/colima · error

error during prune: %w

Error message

error during prune: %w

What it means

`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.

Source

Thrown at cmd/prune.go:42

	Use:   "prune",
	Short: "prune cached downloaded assets",
	Long:  `Prune cached downloaded assets`,
	Args:  cobra.MaximumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		colimaCacheDir := config.CacheDir()
		limaCacheDir := filepath.Join(filepath.Dir(colimaCacheDir), "lima")
		if !pruneCmdArgs.force {
			msg := "'" + colimaCacheDir + "' will be emptied, are you sure"
			if pruneCmdArgs.all {
				msg = "'" + colimaCacheDir + "' and '" + limaCacheDir + "' will be emptied, are you sure"
			}
			if y := cli.Prompt(msg); !y {
				return nil
			}
		}
		logrus.Info("Pruning ", strconv.Quote(config.CacheDir()))
		if err := os.RemoveAll(config.CacheDir()); err != nil {
			return fmt.Errorf("error during prune: %w", err)
		}

		if pruneCmdArgs.all {
			cmd := limautil.Limactl("prune")
			if err := cmd.Run(); err != nil {
				return fmt.Errorf("error during Lima prune: %w", err)
			}
		}

		return nil
	},
}

func init() {
	root.Cmd().AddCommand(pruneCmd)

	pruneCmd.Flags().BoolVarP(&pruneCmdArgs.force, "force", "f", false, "do not prompt for yes/no")
	pruneCmd.Flags().BoolVarP(&pruneCmdArgs.all, "all", "a", false, "include Lima assets")

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. 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`
  2. Or remove directly with elevated rights: `sudo rm -rf <cachedir>` — the path is printed in the 'Pruning ...' log line
  3. Stop colima first (`colima stop`) so nothing in the cache is held open, then prune

Example fix

# before
$ colima prune --force
error: error during prune: ... permission denied

# after
$ sudo chown -R "$USER":staff ~/.cache/colima   # or the logged CacheDir
$ colima prune --force
Defensive patterns

Strategy: try-catch

Validate before calling

// verify you can actually write/delete in the cache dir before pruning
func removable(dir string) bool {
    f, err := os.CreateTemp(dir, ".probe-*")
    if err != nil {
        return false // not writable -> prune will fail
    }
    return os.Remove(f.Name()) == nil
}

Try / catch

if err := pruneCmd.Execute(); err != nil {
    if errors.Is(err, fs.ErrPermission) {
        // escalate deliberately: sudo chown -R $USER <cachedir> (or sudo rm -rf), then retry
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/a83f8033272cd52c. Report an issue: GitHub.