{"record":{"id":"26190c4961feb578","repo":"hyperledger/fabric","slug":"error-executing-template-s","errorCode":null,"errorMessage":"Error executing template: %s","messagePattern":"Error executing template: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cryptogen/main.go","lineNumber":431,"sourceCode":"\t\terr = renderOrgSpec(&orgSpec, \"orderer\")\n\t\tif err != nil {\n\t\t\tfmt.Printf(\"Error processing orderer configuration: %s\", err)\n\t\t\tos.Exit(-1)\n\t\t}\n\t\tgenerateOrdererOrg(*outputDir, orgSpec)\n\t}\n}\n\nfunc parseTemplate(input string, data any) (string, error) {\n\tt, err := template.New(\"parse\").Parse(input)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Error parsing template: %s\", err)\n\t}\n\n\toutput := new(bytes.Buffer)\n\terr = t.Execute(output, data)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Error executing template: %s\", err)\n\t}\n\n\treturn output.String(), nil\n}\n\nfunc parseTemplateWithDefault(input, defaultInput string, data any) (string, error) {\n\t// Use the default if the input is an empty string\n\tif len(input) == 0 {\n\t\tinput = defaultInput\n\t}\n\n\treturn parseTemplate(input, data)\n}\n\nfunc renderNodeSpec(domain string, spec *NodeSpec) error {\n\tdata := SpecData{\n\t\tHostname: spec.Hostname,\n\t\tDomain:   domain,","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/cmd/cryptogen/main.go#L413-L449","documentation":"After a template parses, parseTemplate executes it against the supplied data (node spec fields like Hostname, Domain). If execution fails — typically by referencing a map key/field that does not exist on the data or an invalid method call — this error is returned. Unlike parse errors, this is data/template mismatch at render time.","triggerScenarios":"A crypto-config.yaml template referencing fields not present in the node spec data, e.g. {{.Port}} or {{.User}} where cryptogen only supplies fields like Hostname and Domain; calling a non-existent method on the data value.","commonSituations":"Copy-pasted templates using fields from other tools; renaming data keys after a cryptogen version change; using {{.}} pipelines incompatible with the struct passed in.","solutions":["Read the wrapped execute error; it names the offending field or call in the template.","Restrict template references to fields cryptogen provides (e.g. {{.Hostname}}, {{.Domain}}).","Print the data shape by rendering a minimal template like {{.Hostname}} first.","Check the cryptogen version's supported template fields in the fabric docs."],"exampleFix":"// before\nCommonName: \"{{.Hostname}}.{{.Cluster}}\"\n// after\nCommonName: \"{{.Hostname}}.{{.Domain}}\"","handlingStrategy":"validation","validationCode":"import (\"text/template\"; \"bytes\")\nfunc rendersOK(tmpl string, data any) bool {\n    t, err := template.New(\"probe\").Parse(tmpl)\n    if err != nil { return false }\n    var b bytes.Buffer\n    return t.Execute(&b, data) == nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict template fields to those cryptogen supplies (Hostname, Domain)","Test templates with a minimal render before a full generate","Re-check field names after upgrading cryptogen versions","Avoid copying template examples from unrelated tools"],"tags":["template","cryptogen","go-text-template"],"backgroundTag":"template-execution-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}