abiosoft/colima · error

error writing yaml file: %w

Error message

error writing yaml file: %w

What it means

Save (util/yamlutil/yaml.go:33) writes the encoded config to disk with os.WriteFile and wraps I/O failures. The encode step already succeeded, so the failure is at the filesystem layer: permission denied on the target (usually under ~/.colima or the profile dir), a missing parent directory, a read-only filesystem, or a full disk. colima writes its state and the Lima override YAML through this path during start/stop.

Source

Thrown at util/yamlutil/yaml.go:33

// WriteYAML encodes struct to file as YAML.
func WriteYAML(value any, file string) error {
	b, err := yaml.Marshal(value)
	if err != nil {
		return fmt.Errorf("error encoding YAML: %w", err)
	}

	return os.WriteFile(file, b, 0644)
}

// Save saves the config.
func Save(c config.Config, file string) error {
	b, err := encodeYAML(c)
	if err != nil {
		return err
	}
	if err := os.WriteFile(file, b, 0644); err != nil {
		return fmt.Errorf("error writing yaml file: %w", err)
	}

	return nil
}

func encodeYAML(conf config.Config) ([]byte, error) {
	var doc yaml.Node

	f, err := embedded.Read("defaults/colima.yaml")
	if err != nil {
		return nil, fmt.Errorf("error reading config file: %w", err)
	}

	if err := yaml.Unmarshal(f, &doc); err != nil {
		return nil, fmt.Errorf("embedded default config is invalid yaml: %w", err)
	}

	if l := len(doc.Content); l != 1 {

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Fix ownership of colima state: `sudo chown -R $(id -u):$(id -g) ~/.colima` and retry
  2. Free disk space or move large files off the volume holding ~/.colima
  3. Recreate the missing profile dir (e.g. `mkdir -p ~/.colima/_lima/default`) or `colima delete` then start fresh
  4. Never run colima with sudo unless you will always run it that way

Example fix

# before
$ colima start
error writing yaml file: open /Users/me/.colima/_lima/default/colima.yaml: permission denied

# after
$ sudo chown -R $(id -u):$(id -g) ~/.colima
$ colima start
Defensive patterns

Strategy: validation

Validate before calling

// probe writability of the config dir before saving
func dirWritable(dir string) error {
    f, err := os.OpenFile(filepath.Join(dir, ".probe"), os.O_CREATE|os.O_WRONLY, 0o644)
    if err != nil { return fmt.Errorf("%s not writable (permissions? disk full?): %w", dir, err) }
    _ = f.Close()
    return os.Remove(filepath.Join(dir, ".probe"))
}

Type guard

func isPermissionErr(err error) bool {
    return errors.Is(err, os.ErrPermission) || strings.HasSuffix(err.Error(), "permission denied")
}

Try / catch

if err := util.Save(cfg, file); err != nil {
    if isPermissionErr(err) {
        // guide the user to the sudo-ownership fix instead of a generic failure
        return fmt.Errorf("%w — fix with: sudo chown -R $(id -u):$(id -g) ~/.colima", err)
    }
    return err
}

Prevention

When it happens

Trigger: A previous `sudo colima ...` run left root-owned files in ~/.colima, so the next non-root save gets EACCES; disk full (ENOSPC); the profile directory was deleted mid-operation; the config dir is on a read-only mount.

Common situations: Mixing sudo and non-sudo colima invocations — the single most common cause; macOS disk nearly full; migration/restore of the home directory that changed ownership; security tools blocking writes to dotfile dirs.

Related errors


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