{"record":{"id":"e39059d508bacfb3","repo":"vitessio/vitess","slug":"error-parsing-template-s-w","errorCode":null,"errorMessage":"error parsing template %s: %w","messagePattern":"error parsing template (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtadmin/cluster/discovery/discovery_consul.go","lineNumber":170,"sourceCode":"\tif *vtctldFQDNTmplStr != \"\" {\n\t\tdisco.vtctldFQDNTmpl, err = template.New(\"consul-vtctld-fqdn-template-\" + cluster.Id).Parse(*vtctldFQDNTmplStr)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse vtctld FQDN template %s: %w\", *vtctldFQDNTmplStr, err)\n\t\t}\n\t}\n\n\tdisco.vtctldAddrTmpl, err = template.New(\"consul-vtctld-address-template-\" + cluster.Id).Parse(*vtctldAddrTmplStr)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse vtctld host address template %s: %w\", *vtctldAddrTmplStr, err)\n\t}\n\n\treturn disco, nil\n}\n\nfunc generateConsulDatacenter(component string, cluster *vtadminpb.Cluster, tmplStr string) (string, error) {\n\ttmpl, err := template.New(\"consul-\" + component + \"-datacenter-\" + cluster.Id).Parse(tmplStr)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error parsing template %s: %w\", tmplStr, err)\n\t}\n\n\tdc, err := textutil.ExecuteTemplate(tmpl, &struct {\n\t\tCluster *vtadminpb.Cluster\n\t}{\n\t\tCluster: cluster,\n\t})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to execute template: %w\", err)\n\t}\n\n\treturn dc, nil\n}\n\n// DiscoverVTGate is part of the Discovery interface.\nfunc (c *ConsulDiscovery) DiscoverVTGate(ctx context.Context, tags []string) (*vtadminpb.VTGate, error) {\n\tspan, ctx := trace.NewSpan(ctx, \"ConsulDiscovery.DiscoverVTGate\")\n\tdefer span.Finish()","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtadmin/cluster/discovery/discovery_consul.go#L152-L188","documentation":"generateConsulDatacenter compiles the given datacenter template string with template.New(...).Parse. If parsing fails, this error wraps the raw template string and the parse error; it is propagated up to NewConsul for both the vtgate and vtctld datacenter options. It indicates the template string is syntactically invalid as a Go text/template.","triggerScenarios":"Any NewConsul call with a non-empty vtgate- or vtctld-datacenter-template whose text/template syntax is invalid — unclosed actions, invalid field selectors, or unknown template functions.","commonSituations":"Config generated by templating tools leaving stray braces, hand-written templates with typos, docs examples truncated during copy-paste.","solutions":["Fix the datacenter template string so it parses as a valid Go text/template.","Use only {{ .Cluster }} fields defined in vtadminpb.Cluster, e.g. \"{{ .Cluster.Id }}-dc\".","Clear the datacenter template flag if the option is unused.","Test template strings locally with text/template's Parse before setting them in config."],"exampleFix":"// before\n--vtgate-datacenter-template=\"{{ .Cluster.Id \"\n// after\n--vtgate-datacenter-template=\"{{ .Cluster.Id }}\"","handlingStrategy":"validation","validationCode":"func validateDCTemplate(component, tmplStr string) error {\n    _, err := template.New(\"dc-check\").Parse(tmplStr)\n    return err\n}","typeGuard":null,"tryCatchPattern":"disco, err := NewConsul(cluster, args)\nif err != nil && strings.Contains(err.Error(), \"error parsing template\") {\n    log.Fatalf(\"invalid datacenter template: %v\", err)\n}","preventionTips":["Parse every datacenter template with text/template before wiring it into cluster config.","Restrict templates to {{ .Cluster.* }} field paths from vtadminpb.Cluster.","Store templates in lint-checked config files rather than ad-hoc shell strings."],"tags":["go","template","consul","datacenter"],"backgroundTag":"template-parse-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}