{"record":{"id":"3963cf6b9bd87337","repo":"thanos-io/thanos","slug":"execute-template","errorCode":null,"errorMessage":"execute template","messagePattern":"execute template","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/tools_bucket.go","lineNumber":509,"sourceCode":"\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t}\n\t\tcase \"json\":\n\t\t\tenc := json.NewEncoder(os.Stdout)\n\t\t\tenc.SetIndent(\"\", \"\\t\")\n\n\t\t\tprintBlock = func(m *metadata.Meta) error {\n\t\t\t\treturn enc.Encode(&m)\n\t\t\t}\n\t\tdefault:\n\t\t\ttmpl, err := template.New(\"\").Parse(format)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"invalid template\")\n\t\t\t}\n\t\t\tprintBlock = func(m *metadata.Meta) error {\n\t\t\t\tif err := tmpl.Execute(os.Stdout, &m); err != nil {\n\t\t\t\t\treturn errors.Wrap(err, \"execute template\")\n\t\t\t\t}\n\t\t\t\tfmt.Fprintln(os.Stdout, \"\")\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\n\t\tmetas, _, err := fetcher.Fetch(ctx)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tfor _, meta := range metas {\n\t\t\tobjects++\n\t\t\tif err := printBlock(meta); err != nil {\n\t\t\t\treturn errors.Wrap(err, \"iter\")\n\t\t\t}\n\t\t}\n\t\tlevel.Info(logger).Log(\"msg\", \"ls done\", \"objects\", objects)","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/tools_bucket.go#L491-L527","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nthanos tools bucket ls bkt --format '{{.Thanos.Version}}'\n// after\nthanos tools bucket ls bkt --format '{{.Thana.Version}}'","handlingStrategy":"validation","validationCode":"_, err := template.New(\"\").Parse(format)\nif err != nil {\n    return fmt.Errorf(\"--format template is invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := printBlock(meta); err != nil {\n    if strings.Contains(err.Error(), \"execute template\") {\n        // fall back to default format\n        format = \"{{.ULID}}\"\n    }\n}","preventionTips":["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"],"tags":["go-template","cli","template-execution"],"backgroundTag":"invalid-argument-value","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}