amir20/dozzle · error

failed to execute template field

Error message

failed to execute template field %q: %w

What it means

After a string field's template parses successfully, resolveTemplateValues executes it against the notification data. This error is returned when tmpl.Execute fails at render time, typically because the template references a key absent from the data map or applies an invalid operation to a data value. The whole template resolution aborts so no partially-rendered webhook payload is sent.

Solutions

  1. Inspect the wrapped execute error; for missing keys it names the field that could not be evaluated.
  2. Align the placeholder paths with the actual notification data structure (correct key names and nesting).
  3. Use conditional/default rendering like '{{ if .Field }}{{ .Field }}{{ end }}' or sprig-style defaults if the field may be absent.
  4. Test the template with a sample payload via SendTest before relying on it.

Example fix

// before (deep path that may not exist)
{"text": "{{ .Container.Labels.dev.dozzle.name }}"}
// after (guard against absence)
{"text": "{{ if .Container }}{{ .Container.Name }}{{ end }}"}
Defensive patterns

Strategy: try-catch

Validate before calling

// Execute against a sample payload before persisting the template
if _, err := resolveTemplateValues(sampleStructure, sampleData); err != nil {
    return fmt.Errorf("template incompatible with data schema: %w", err)
}

Try / catch

if err := tmpl.Execute(&buf, data); err != nil {
    log.Printf("field %q failed to render, check data keys: %v", val, err)
    return fallbackValue
}

Prevention

When it happens

Trigger: A per-field template like '{{ .Missing }}' or '{{ .Level.SomeDeep.Field }}' executed against data that lacks that key or shape; also triggered by invalid pipeline usage (e.g. calling a non-function). Raised inside resolveTemplateValues via executeJSONTemplate.

Common situations: Users write placeholders against an imagined data schema (wrong key casing, deep JSON paths that don't exist), or reuse templates copied from another tool whose field names differ.

Related errors


AI-assisted analysis of amir20/dozzle@d9463cbe21 (2026-09-07). Data as JSON: /api/errors/aa9ef9836d119aa6. Report an issue: GitHub.

Appendix: source

Thrown at internal/notification/dispatcher/webhook.go:333

		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)