abiosoft/colima · error
error parsing template: %w
Error message
error parsing template: %w
What it means
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.
Source
Thrown at util/template.go:23
"fmt"
"os"
"text/template"
)
// WriteTemplate writes template with body to file after applying values.
func WriteTemplate(body string, file string, values any) error {
b, err := ParseTemplate(body, values)
if err != nil {
return err
}
return os.WriteFile(file, b, 0644)
}
// ParseTemplate parses template with body and values and returns the resulting bytes.
func ParseTemplate(body string, values any) ([]byte, error) {
t, err := template.New("").Parse(body)
if err != nil {
return nil, fmt.Errorf("error parsing template: %w", err)
}
var b bytes.Buffer
if err := t.Execute(&b, values); err != nil {
return nil, fmt.Errorf("error executing template: %w", err)
}
return b.Bytes(), err
}
View on GitHub (pinned to c3a5f9184d)
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
Example fix
// before
body := "echo {{.InstanceId" // unterminated action
b, err := util.ParseTemplate(body, values)
// after
body := "echo {{.InstanceId}}"
b, err := util.ParseTemplate(body, values) Defensive patterns
Strategy: validation
Validate before calling
// pre-parse templates at startup/test time to catch syntax errors early
func templateIsValid(body string) bool {
_, err := template.New("").Parse(body)
return err == nil
} Try / catch
b, err := util.ParseTemplate(body, values)
if err != nil {
// the wrapped cause names the line/column of the syntax error — surface it verbatim
return fmt.Errorf("rendering failed: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- error executing template: %w
- invalid pid: %v
- error applying nerdctl script template: %w
- error reading embedded file: %w
- error reading template file: %w
AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15).
Data as JSON: /api/errors/2f44495c5b82ad1a.
Report an issue: GitHub.