abiosoft/colima · error
error saving template: %w
Error message
error saving template: %w
What it means
Returned by `colima template` when configmanager.SaveToFile cannot write the validated config to the template path (TemplatesDir()/default.yaml, printable via `colima template --print`). The YAML is already valid at this point, so failures are filesystem-level: permission denied on the templates dir, read-only filesystem, or disk full. TemplatesDir is a requiredDir that is mkdir'd on access, so a missing directory normally cannot cause this.
Source
Thrown at cmd/template.go:61
tmpFile, err := waitForUserEdit(templateCmdArgs.Editor, []byte(abort+"\n"+info+"\n"+template))
if err != nil {
return fmt.Errorf("error editing template file: %w", err)
}
if tmpFile == "" {
return fmt.Errorf("empty file, template edit aborted")
}
defer func() {
_ = os.Remove(tmpFile)
}()
// load and resave template to ensure the format is correct
cf, err := configmanager.LoadFrom(tmpFile)
if err != nil {
return fmt.Errorf("error in template: %w", err)
}
if err := configmanager.SaveToFile(cf, templateFile()); err != nil {
return fmt.Errorf("error saving template: %w", err)
}
log.Println("configurations template saved")
return nil
},
}
func templateFile() string { return filepath.Join(config.TemplatesDir(), "default.yaml") }
func templateFileOrDefault() (string, error) {
tFile := templateFile()
if _, err := os.Stat(tFile); err == nil {
b, err := os.ReadFile(tFile)
if err == nil {
return string(b), nil
}
}View on GitHub (pinned to c3a5f9184d)
Solutions
- Fix ownership of the colima config tree: `sudo chown -R "$USER" ~/.colima`
- Free disk space and retry `colima template`
- Confirm the target path and its permissions: `colima template --print` then `ls -ld` its parent directory
- As a workaround, write the file with correct ownership manually from your validated YAML
Example fix
# before $ colima template # (edit, save) Error: error saving template: open ~/.colima/_templates/default.yaml: permission denied # after $ sudo chown -R "$USER" ~/.colima $ colima template
Defensive patterns
Strategy: validation
Validate before calling
// Probe writability of the template destination before the interactive round-trip
out, _ := exec.Command("colima", "template", "--print").Output()
tpl := strings.TrimSpace(string(out)) // last line is the path
if probe, err := os.CreateTemp(filepath.Dir(tpl), "probe-*"); err != nil {
log.Fatalf("templates dir not writable: %v", err)
} else {
probe.Close()
os.Remove(probe.Name())
} Prevention
- Never run colima under sudo; fix ownership with chown if already root-owned
- Keep disk space headroom before interactive config/template edits
- Note the edit is validated before saving — invalid YAML fails earlier as 'error in template'
When it happens
Trigger: Templates dir owned by root (earlier sudo use) making the write fail with EACCES; disk full (ENOSPC) when flushing the file; security software blocking writes under ~/.colima.
Common situations: Running colima once under sudo then as the normal user; full disks; corporate endpoint protection quarantining writes to dotdirs.
Related errors
- error persisting runtime settings: %w
- error persisting kubernetes settings: %w
- error deleting configs: %w
- error reading ssh config: %w
- error modifying %s: %w
AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15).
Data as JSON: /api/errors/ec73eff982bd3977.
Report an issue: GitHub.