{"record":{"id":"ec73eff982bd3977","repo":"abiosoft/colima","slug":"error-saving-template-w","errorCode":null,"errorMessage":"error saving template: %w","messagePattern":"error saving template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/template.go","lineNumber":61,"sourceCode":"\n\t\ttmpFile, err := waitForUserEdit(templateCmdArgs.Editor, []byte(abort+\"\\n\"+info+\"\\n\"+template))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error editing template file: %w\", err)\n\t\t}\n\t\tif tmpFile == \"\" {\n\t\t\treturn fmt.Errorf(\"empty file, template edit aborted\")\n\t\t}\n\t\tdefer func() {\n\t\t\t_ = os.Remove(tmpFile)\n\t\t}()\n\n\t\t// load and resave template to ensure the format is correct\n\t\tcf, err := configmanager.LoadFrom(tmpFile)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error in template: %w\", err)\n\t\t}\n\t\tif err := configmanager.SaveToFile(cf, templateFile()); err != nil {\n\t\t\treturn fmt.Errorf(\"error saving template: %w\", err)\n\t\t}\n\n\t\tlog.Println(\"configurations template saved\")\n\n\t\treturn nil\n\t},\n}\n\nfunc templateFile() string { return filepath.Join(config.TemplatesDir(), \"default.yaml\") }\n\nfunc templateFileOrDefault() (string, error) {\n\ttFile := templateFile()\n\tif _, err := os.Stat(tFile); err == nil {\n\t\tb, err := os.ReadFile(tFile)\n\t\tif err == nil {\n\t\t\treturn string(b), nil\n\t\t}\n\t}","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/cmd/template.go#L43-L79","documentation":"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.","triggerScenarios":"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.","commonSituations":"Running colima once under sudo then as the normal user; full disks; corporate endpoint protection quarantining writes to dotdirs.","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"],"exampleFix":"# before\n$ colima template   # (edit, save)\nError: error saving template: open ~/.colima/_templates/default.yaml: permission denied\n\n# after\n$ sudo chown -R \"$USER\" ~/.colima\n$ colima template","handlingStrategy":"validation","validationCode":"// Probe writability of the template destination before the interactive round-trip\nout, _ := exec.Command(\"colima\", \"template\", \"--print\").Output()\ntpl := strings.TrimSpace(string(out)) // last line is the path\nif probe, err := os.CreateTemp(filepath.Dir(tpl), \"probe-*\"); err != nil {\n    log.Fatalf(\"templates dir not writable: %v\", err)\n} else {\n    probe.Close()\n    os.Remove(probe.Name())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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'"],"tags":["filesystem","permissions","template","save"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}