{"record":{"id":"93225ff6aa8be0a8","repo":"vitessio/vitess","slug":"failed-to-generate-vtctld-consul-datacenter-from-t","errorCode":null,"errorMessage":"failed to generate vtctld consul datacenter from template: %w","messagePattern":"failed to generate vtctld consul datacenter from template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtadmin/cluster/discovery/discovery_consul.go","lineNumber":148,"sourceCode":"\t}\n\n\tif *vtgateFQDNTmplStr != \"\" {\n\t\tdisco.vtgateFQDNTmpl, err = template.New(\"consul-vtgate-fqdn-template-\" + cluster.Id).Parse(*vtgateFQDNTmplStr)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse vtgate FQDN template %s: %w\", *vtgateFQDNTmplStr, err)\n\t\t}\n\t}\n\n\tdisco.vtgateAddrTmpl, err = template.New(\"consul-vtgate-address-template-\" + cluster.Id).Parse(*vtgateAddrTmplStr)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse vtgate host address template %s: %w\", *vtgateAddrTmplStr, err)\n\t}\n\n\t/* vtctld options */\n\tif *vtctldDatacenterTmplStr != \"\" {\n\t\tdisco.vtctldDatacenter, err = generateConsulDatacenter(\"vtctld\", cluster, *vtctldDatacenterTmplStr)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to generate vtctld consul datacenter from template: %w\", err)\n\t\t}\n\t}\n\n\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","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtadmin/cluster/discovery/discovery_consul.go#L130-L166","documentation":"Analogous to the vtgate case, NewConsul renders the optional vtctld datacenter template via generateConsulDatacenter and wraps any parse/execute failure with this message. It signals that the vtctld datacenter template string is invalid or cannot be rendered against the cluster proto.","triggerScenarios":"Passing a non-empty vtctld-datacenter-template flag whose Go template fails to parse (syntax error) or whose execution against &struct{Cluster *vtadminpb.Cluster} fails, during NewConsul.","commonSituations":"Invalid template syntax from manual edits, referencing nonexistent Cluster fields, environment/config tooling mangling braces, copy-paste between vtgate and vtctld flags introducing a typo.","solutions":["Fix the vtctld datacenter template syntax to be a valid Go text/template.","Reference only valid vtadminpb.Cluster fields (e.g. {{ .Cluster.Id }}).","Leave the vtctld datacenter template empty to skip the feature — it is only parsed when non-empty.","Read the wrapped inner error to distinguish parse vs execution failure."],"exampleFix":"// before\n--vtctld-datacenter-template=\"{{ if .Cluster.Id }}dc1\"\n// after\n--vtctld-datacenter-template=\"{{ if .Cluster.Id }}dc1{{ end }}\"","handlingStrategy":"validation","validationCode":"if s := *vtctldDatacenterTmplStr; s != \"\" {\n    if _, err := template.New(\"check\").Parse(s); err != nil {\n        return fmt.Errorf(\"invalid vtctld dc template: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"disco, err := NewConsul(cluster, args)\nif err != nil && strings.Contains(err.Error(), \"vtctld consul datacenter\") {\n    log.Fatalf(\"bad vtctld datacenter template: %v\", err)\n}","preventionTips":["Mirror the vtgate template only after verifying its syntax.","Guard nil fields with {{ if }} ... {{ end }} when rendering Cluster data.","Validate all non-empty template flags at config load time."],"tags":["go","template","consul","vtctld","config"],"backgroundTag":"template-parse-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}