{"record":{"id":"13c3c5f45c6a8f97","repo":"abiosoft/colima","slug":"error-in-template-w","errorCode":null,"errorMessage":"error in template: %w","messagePattern":"error in template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/template.go","lineNumber":58,"sourceCode":"\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error reading template file: %w\", err)\n\t\t}\n\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 {","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/cmd/template.go#L40-L76","documentation":"Returned by `colima template` when configmanager.LoadFrom(tmpFile) fails to parse the edited temp file — the round-trip that validates the user's YAML before it is saved as the template. LoadFrom errors on read failure or yaml.Unmarshal failure, so this means the edited content is invalid YAML or has values that do not fit the config schema (wrong types, bad structure).","triggerScenarios":"Saving the template buffer with tab indentation, broken nesting, or scalar types that do not unmarshal into config.Config fields; editor inserting template placeholders like ${var}; truncation mid-write.","commonSituations":"YAML beginners using tabs instead of spaces; copy-pasting fragments with inconsistent indentation; VS Code auto-format mangling comment-headered YAML.","solutions":["Re-run `colima template` and fix the reported line/column from the wrapped yaml error","Replace tabs with spaces and keep 2-space indentation matching the default config","Start from the pristine default: delete the on-disk template (`rm \"$(colima template --print | tail -1)\"`) so the embedded default is prefilled, then edit minimally","Validate before saving: paste the buffer into `yamllint` or `kubectl create --dry-run`-style YAML checkers"],"exampleFix":"# before: buffer saved with a tab before 'cpus'\nError: error in template: could not load config from file: yaml: line 4: found character that cannot start any token\n\n# after: spaces only\ncpus: 4\nmemory: 8","handlingStrategy":"validation","validationCode":"// Dry-run parse the intended template before putting it in front of a user\nfunc validTemplate(y string) error {\n    var c config.Config\n    if err := yaml.Unmarshal([]byte(y), &c); err != nil {\n        return fmt.Errorf(\"template YAML invalid: %w\", err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := templateCmd.Execute(); err != nil {\n    var yte *yaml.TypeError\n    if errors.As(err, &yte) { // navigate wrapped chain via errors.Unwrap as needed\n        // show yte.Errors (line/col) to pinpoint the bad lines\n    }\n}","preventionTips":["Use spaces (2-indent), never tabs, in colima YAML","Keep the commented abort/info headers intact and edit only real keys","Lint edited YAML with yamllint before saving from the editor"],"tags":["yaml","template","validation","edit"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}