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

  1. Read the wrapped parse error (%w cause); it names the exact field value and the syntax problem with a line/column.
  2. Fix the template syntax in the offending field: balance all {{ }} pairs and close any range/if blocks with {{end}}.
  3. 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

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

Related errors


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)