abiosoft/colima · error

error preparing config file: %w

Error message

error preparing config file: %w

What it means

Raised in PreRunE of `colima start` when --save-config (-s) is set and configmanager.Save fails to persist the merged config to the current profile's config file. Save serializes to YAML and writes via yamlutil.Save to config.CurrentProfile().File(), so failures are filesystem-level: unreadable/unwritable path, permission denied, disk full, or a directory where the file should be.

Source

Thrown at cmd/start.go:106

	},
	PreRunE: func(cmd *cobra.Command, args []string) error {
		// validate Lima version
		if err := core.LimaVersionSupported(); err != nil {
			return fmt.Errorf("lima compatibility error: %w", err)
		}

		// combine args and current config file(if any)
		prepareConfig(cmd)

		// validate config
		if err := configmanager.ValidateConfig(startCmdArgs.Config); err != nil {
			return fmt.Errorf("error in config: %w", err)
		}

		// persist in preparation for application start
		if startCmdArgs.Flags.SaveConfig {
			if err := configmanager.Save(startCmdArgs.Config); err != nil {
				return fmt.Errorf("error preparing config file: %w", err)
			}
		}

		// validate and set downloader if flag is specified (takes precedence over env var)
		if cmd.Flag("downloader").Changed {
			normalized, err := downloader.ValidateDownloader(startCmdArgs.Flags.Downloader)
			if err != nil {
				return err
			}
			downloader.SetDownloader(normalized)
		}

		return nil
	},
}

const (
	defaultCPU               = 2

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Inspect the wrapped error for the path and syscall (permission denied vs no space etc.)
  2. Fix ownership/permissions of the config dir: `ls -la ~/.colima` and `sudo chown -R "$USER" ~/.colima` if it is root-owned
  3. Free disk space or repair the filesystem if the write failed with ENOSPC/EIO
  4. Ensure HOME (or COLIMA_HOME) is set and writable in the environment invoking colima

Example fix

# before
$ colima start -s --cpus 4
Error: error preparing config file: open ~/.colima/_config/colima.yaml: permission denied

# after
$ sudo chown -R "$USER" ~/.colima
$ colima start -s --cpus 4
Defensive patterns

Strategy: validation

Validate before calling

// Before `colima start -s`: ensure the profile config path is writable
home, _ := os.UserHomeDir()
dir := filepath.Join(home, ".colima") // or honor COLIMA_HOME / XDG_CONFIG_HOME
if info, err := os.Stat(dir); err != nil || !info.IsDir() {
    if err := os.MkdirAll(dir, 0o755); err != nil {
        log.Fatalf("cannot create config dir: %v", err)
    }
}
if probe, err := os.CreateTemp(dir, "probe-*"); err != nil {
    log.Fatalf("config dir not writable: %v", err)
} else {
    probe.Close()
    os.Remove(probe.Name())
}

Prevention

When it happens

Trigger: `colima start -s ...` when ~/.colima (or the COLIMA_HOME/XDG config dir) has wrong ownership or is read-only; HOME unset so the profile path cannot resolve; disk full at write time.

Common situations: Running colima under a different user/sudo so ~/.colima is root-owned; read-only or full disk; HOME pointing to a nonexistent directory in CI or launchd contexts.

Related errors


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