hyperledger/fabric · error

Error executing template: %s

Error message

Error executing template: %s

What it means

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.

Source

Thrown at cmd/cryptogen/main.go:431

		err = renderOrgSpec(&orgSpec, "orderer")
		if err != nil {
			fmt.Printf("Error processing orderer configuration: %s", err)
			os.Exit(-1)
		}
		generateOrdererOrg(*outputDir, orgSpec)
	}
}

func parseTemplate(input string, data any) (string, error) {
	t, err := template.New("parse").Parse(input)
	if err != nil {
		return "", fmt.Errorf("Error parsing template: %s", err)
	}

	output := new(bytes.Buffer)
	err = t.Execute(output, data)
	if err != nil {
		return "", fmt.Errorf("Error executing template: %s", err)
	}

	return output.String(), nil
}

func parseTemplateWithDefault(input, defaultInput string, data any) (string, error) {
	// Use the default if the input is an empty string
	if len(input) == 0 {
		input = defaultInput
	}

	return parseTemplate(input, data)
}

func renderNodeSpec(domain string, spec *NodeSpec) error {
	data := SpecData{
		Hostname: spec.Hostname,
		Domain:   domain,

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Read the wrapped execute error; it names the offending field or call in the template.
  2. Restrict template references to fields cryptogen provides (e.g. {{.Hostname}}, {{.Domain}}).
  3. Print the data shape by rendering a minimal template like {{.Hostname}} first.
  4. Check the cryptogen version's supported template fields in the fabric docs.

Example fix

// before
CommonName: "{{.Hostname}}.{{.Cluster}}"
// after
CommonName: "{{.Hostname}}.{{.Domain}}"
Defensive patterns

Strategy: validation

Validate before calling

import ("text/template"; "bytes")
func rendersOK(tmpl string, data any) bool {
    t, err := template.New("probe").Parse(tmpl)
    if err != nil { return false }
    var b bytes.Buffer
    return t.Execute(&b, data) == nil
}

Prevention

When it happens

Trigger: 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.

Common situations: Copy-pasted templates using fields from other tools; renaming data keys after a cryptogen version change; using {{.}} pipelines incompatible with the struct passed in.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/26190c4961feb578. Report an issue: GitHub.