amir20/dozzle · error
failed to parse template field
Error message
failed to parse template field %q: %w
What it means
resolveTemplateValues walks the JSON template structure and, for any string value containing '{{', parses it as a Go text/template. This error is returned from template.Parse when the field's template syntax is invalid (unbalanced braces, bad action syntax, unknown functions at parse time). The field is never executed because parsing failed first.
Solutions
- Read the wrapped parse error (%w cause); it names the exact field value and the syntax problem with a line/column.
- Fix the template syntax in the offending field: balance all {{ }} pairs and close any range/if blocks with {{end}}.
- If the braces are meant literally (not a placeholder), escape them or remove them so the field skips template parsing (fields without '{{' are returned as-is).
Example fix
// before (unclosed action)
{"text": "Container {{ .Name is down"}
// after
{"text": "Container {{ .Name }} is down"} Defensive patterns
Strategy: validation
Validate before calling
if strings.Contains(val, "{{") {
if _, err := template.New("check").Parse(val); err != nil {
return fmt.Errorf("invalid template field %q: %w", val, err)
}
} Try / catch
resolved, err := resolveTemplateValues(structure, data)
if err != nil {
return nil, fmt.Errorf("check webhook template syntax (balanced {{ }}): %w", err)
} Prevention
- Balance every {{ with a }} before saving templates.
- Close every {{ range }}/{{ if }} with {{ end }}.
- Validate templates in the UI at save time, not at dispatch time.
When it happens
Trigger: Any string field inside the webhook JSON structure that contains '{{' but has malformed template syntax: '{{ .Field' (missing closing braces), '{{range}}' without '{{end}}', or invalid action syntax. Raised inside resolveTemplateValues, which is called recursively by executeJSONTemplate.
Common situations: Users paste JSON with placeholders and accidentally delete a closing brace, mix template delimiters with shell ${} syntax, or write Go template actions with the wrong keyword.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse template
- failed to execute template
- failed to execute template field
- Failed to save destination
- invalid format: key is empty
AI-assisted analysis of amir20/dozzle@d9463cbe21 (2026-09-07).
Data as JSON: /api/errors/0eab83018e5ba728.
Report an issue: GitHub.
Appendix: source
Thrown at internal/notification/dispatcher/webhook.go:329
}
return result, nil
case []any:
result := make([]any, len(val))
for i, child := range val {
resolved, err := resolveTemplateValues(child, data)
if err != nil {
return nil, err
}
result[i] = resolved
}
return result, nil
case string:
if !strings.Contains(val, "{{") {
return val, nil
}
tmpl, err := template.New("field").Parse(val)
if err != nil {
return nil, fmt.Errorf("failed to parse template field %q: %w", val, err)
}
var buf bytes.Buffer
if err := tmpl.Execute(&buf, data); err != nil {
return nil, fmt.Errorf("failed to execute template field %q: %w", val, err)
}
return buf.String(), nil
default:
return val, nil
}
}
View on GitHub (pinned to d9463cbe21)