{"record":{"id":"2f44495c5b82ad1a","repo":"abiosoft/colima","slug":"error-parsing-template-w","errorCode":null,"errorMessage":"error parsing template: %w","messagePattern":"error parsing template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/template.go","lineNumber":23,"sourceCode":"\t\"fmt\"\n\t\"os\"\n\t\"text/template\"\n)\n\n// WriteTemplate writes template with body to file after applying values.\nfunc WriteTemplate(body string, file string, values any) error {\n\tb, err := ParseTemplate(body, values)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn os.WriteFile(file, b, 0644)\n}\n\n// ParseTemplate parses template with body and values and returns the resulting bytes.\nfunc ParseTemplate(body string, values any) ([]byte, error) {\n\tt, err := template.New(\"\").Parse(body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing template: %w\", err)\n\t}\n\n\tvar b bytes.Buffer\n\tif err := t.Execute(&b, values); err != nil {\n\t\treturn nil, fmt.Errorf(\"error executing template: %w\", err)\n\t}\n\n\treturn b.Bytes(), err\n}\n","sourceCodeStart":5,"sourceCodeEnd":33,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/util/template.go#L5-L33","documentation":"ParseTemplate (util/template.go:23) calls text/template's Parse on the body string; this error wraps a syntax-level failure, meaning the template text itself is malformed (unclosed {{, stray }}, bad pipeline, invalid action). colima uses ParseTemplate to render Lima config snippets and provisioning scripts (e.g. the disk mount script), so the body is normally a hardcoded, already-valid template. Seeing this error means a template literal was edited and broke Go template syntax.","triggerScenarios":"Calling util.ParseTemplate(body, values) with a body like \"{{.InstanceId\" (missing closing braces), \"{{ end }}\" without an opening block, or a body containing a literal \"{{\" that was meant as plain text.","commonSituations":"Editing embedded template literals (disk scripts, cloud-init, Lima override files) in a colima fork and introducing a typo; user-supplied strings containing raw braces being concatenated into a template; copy-pasting shell scripts with {{ }} into a template without escaping.","solutions":["Fix the template syntax: balance every {{ with }} and validate action syntax against text/template docs","Escape literal braces as {{\"{{\"}} and {{\"}}\"}} instead of raw {{ }}","Add a unit test that runs ParseTemplate over the embedded template body so syntax errors fail at build/test time","If the text is not meant to be a template at all, pass it through directly instead of ParseTemplate"],"exampleFix":"// before\nbody := \"echo {{.InstanceId\" // unterminated action\nb, err := util.ParseTemplate(body, values)\n\n// after\nbody := \"echo {{.InstanceId}}\"\nb, err := util.ParseTemplate(body, values)","handlingStrategy":"validation","validationCode":"// pre-parse templates at startup/test time to catch syntax errors early\nfunc templateIsValid(body string) bool {\n    _, err := template.New(\"\").Parse(body)\n    return err == nil\n}","typeGuard":null,"tryCatchPattern":"b, err := util.ParseTemplate(body, values)\nif err != nil {\n    // the wrapped cause names the line/column of the syntax error — surface it verbatim\n    return fmt.Errorf(\"rendering failed: %w\", err)\n}","preventionTips":["Keep template literals in consts next to a unit test that parses them","Escape literal braces with {{\"{{\"}} never raw {{","Run `go test` after any template edit","Never feed unescaped user input into template bodies"],"tags":["template","go-template","syntax","parsing"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}