abiosoft/colima · error
error executing template: %w
Error message
error executing template: %w
What it means
ParseTemplate (util/template.go:28) fails at t.Execute when the template parses fine but references data that the values object cannot supply — for structs this is 'can't evaluate field X in type Y', for maps a missing key, or a invoked function/method returning an error mid-render. The wrapped error identifies which field/key and template line caused it. In colima the values structs are small and fixed (e.g. {Format, InstanceId}), so this usually means template and values struct drifted apart.
Source
Thrown at util/template.go:28
// 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
- Align every {{.Field}} in the body with exported fields (exact names, case-sensitive) of the values struct
- Guard optional values with {{if .Field}}...{{end}} instead of dereferencing blindly
- Dry-run t.Execute(io.Discard, values) in a unit test with the real values type to catch drift
- For map values, ensure keys exist or use {{index . "key"}} with an {{if}} existence check
Example fix
// before
values := struct{ Format bool; InstanceId string }{...}
body := "{{.Formats}}" // field name typo -> execute error
// after
body := "{{.Format}}" Defensive patterns
Strategy: validation
Validate before calling
// dry-run execution catches field-name drift before it matters
func templateExecutes(body string, values any) error {
t, err := template.New("").Parse(body)
if err != nil { return err }
return t.Execute(io.Discard, values)
} Type guard
func isTemplateExecError(err error) bool {
var e *template.ExecError
return errors.As(err, &e)
} Try / catch
if b, err := util.ParseTemplate(body, values); err != nil {
if isTemplateExecError(err) {
// template/data mismatch: report field name and template line to the user
return fmt.Errorf("template references unknown field: %w", err)
}
return err
} Prevention
- Unit-test ParseTemplate with the exact values type used in production
- Use {{if .Field}} around optional references
- Update templates in the same commit that renames struct fields
- Prefer map[string]any with documented keys for externally-authored templates
When it happens
Trigger: Template contains {{.Formats}} while values is struct{ Format bool; InstanceId string }; passing a map[string]any whose key set doesn't cover the template's references; a custom function used in the template returns an error.
Common situations: Renaming a struct field without updating the template literal; passing values of the wrong type into a helper that reuses ParseTemplate; templates written against an older struct shape after a colima upgrade in a fork.
Related errors
- error parsing template: %w
- error provisioning %s: %w
- error starting %s: %w
- error retrieving runtimes: %w
- error stopping %s: %w
AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15).
Data as JSON: /api/errors/341c83d455cd8d23.
Report an issue: GitHub.