{"record":{"id":"725990fe32510177","repo":"hyperledger/fabric","slug":"error-parsing-template-s","errorCode":null,"errorMessage":"Error parsing template: %s","messagePattern":"Error parsing template: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cryptogen/main.go","lineNumber":425,"sourceCode":"\t\t\tos.Exit(-1)\n\t\t}\n\t\tgeneratePeerOrg(*outputDir, orgSpec)\n\t}\n\n\tfor _, orgSpec := range config.OrdererOrgs {\n\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)","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/cmd/cryptogen/main.go#L407-L443","documentation":"parseTemplate compiles a Go text/template string used in cryptogen's config (e.g. for SANS, CommonName, or hostname patterns like '{{.Hostname}}'). If the template syntax itself is invalid, template.Parse fails and this error is returned before any data is applied. This is a template compile-time error, independent of the data.","triggerScenarios":"A crypto-config.yaml field containing '{{' template syntax that does not parse: unbalanced braces, unknown/missing 'end' for if/range, or invalid pipeline syntax in fields such as Hostname, SANS, or CommonName templates.","commonSituations":"Typos like '{{.Hostname}' (single closing brace) or '{{hostname}}' misuse; partial templates accidentally truncated by YAML editing; users pasting Go template examples with functions unavailable in text/template.","solutions":["Read the wrapped template error which names the line and issue in the template string.","Balance all {{ }} delimiters and close if/range/with blocks with {{end}}.","Only use fields/functions available to cryptogen templates, e.g. {{.Hostname}}, {{.Domain}}.","If the value is literal text, remove the '{{' characters so it is not treated as a template."],"exampleFix":"// before (yaml)\nSANS:\n  - \"{{.Hostname}.{{.Domain}}\"\n// after\nSANS:\n  - \"{{.Hostname}}.{{.Domain}}\"","handlingStrategy":"validation","validationCode":"import (\"text/template\"; \"bytes\")\nfunc validTemplate(s string) bool {\n    _, err := template.New(\"probe\").Parse(s)\n    return err == nil\n}\n// apply to each templated yaml field before running cryptogen","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Balance every {{ with a matching }}","Close if/range/with blocks with {{end}}","Only use documented cryptogen fields like {{.Hostname}} and {{.Domain}}","Escape literal braces or remove template syntax from plain-text values"],"tags":["template","cryptogen","go-text-template"],"backgroundTag":"template-syntax-error","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"}