thanos-io/thanos · error
execute template
Error message
execute template
What it means
The `thanos tools bucket web` / inspect command parses the user-supplied Go template (via --format) and executes it against each block's *metadata.Meta. This error wraps any failure returned by tmpl.Execute, e.g. the template references a field that does not exist on metadata.Meta or a template function misuse. It indicates the template text is syntactically valid but cannot be evaluated against the data.
Solutions
- Check every field reference in --format against the metadata.Meta struct (github.com/thanos-io/thanos/pkg/block/metadata) and fix names.
- Guard possibly-nil pointer fields in the template, e.g. {{if .Thana}}...{{end}}, since m is passed as *metadata.Meta.
- Verify with `template.New("").Parse` + Execute in a small Go snippet to see the precise field/function error.
- If a field was removed in a Thanos upgrade, update the template to the new field name.
Example fix
// before
thanos tools bucket ls bkt --format '{{.Thanos.Version}}'
// after
thanos tools bucket ls bkt --format '{{.Thana.Version}}' Defensive patterns
Strategy: validation
Validate before calling
_, err := template.New("").Parse(format)
if err != nil {
return fmt.Errorf("--format template is invalid: %w", err)
} Try / catch
if err := printBlock(meta); err != nil {
if strings.Contains(err.Error(), "execute template") {
// fall back to default format
format = "{{.ULID}}"
}
} Prevention
- Only reference fields that exist on metadata.Meta in --format templates
- Guard optional pointer fields with {{if ...}}
- Test templates on a single block ID before full bucket runs
- Check the metadata.Meta struct for your exact Thanos version after upgrades
When it happens
Trigger: Running `thanos tools bucket inspect/web/ls` (the printBlock path at cmd/thanos/tools_bucket.go:509) with a --format template like '{{.Thana.Oops}}' that accesses a nonexistent field of metadata.Meta, calls a method that errors, or uses an undefined template function.
Common situations: Copy-pasted templates from older Thanos versions where metadata.Meta fields were renamed/removed (e.g. downsampling or source fields), typos in field names (Go templates fail on nil-pointer field access), or templates written for Prometheus meta JSON instead of Thanos metadata.Meta.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- iter
- level is bigger then default set of
- unknown sync strategy
- get compaction levels
- penalty based deduplication needs at least one replica…
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/3963cf6b9bd87337.
Report an issue: GitHub.
Appendix: source
Thrown at cmd/thanos/tools_bucket.go:509
return err
}
return nil
}
case "json":
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", "\t")
printBlock = func(m *metadata.Meta) error {
return enc.Encode(&m)
}
default:
tmpl, err := template.New("").Parse(format)
if err != nil {
return errors.Wrap(err, "invalid template")
}
printBlock = func(m *metadata.Meta) error {
if err := tmpl.Execute(os.Stdout, &m); err != nil {
return errors.Wrap(err, "execute template")
}
fmt.Fprintln(os.Stdout, "")
return nil
}
}
metas, _, err := fetcher.Fetch(ctx)
if err != nil {
return err
}
for _, meta := range metas {
objects++
if err := printBlock(meta); err != nil {
return errors.Wrap(err, "iter")
}
}
level.Info(logger).Log("msg", "ls done", "objects", objects)View on GitHub (pinned to 35b8b99117)