hyperledger/fabric · error

Error parsing template: %s

Error message

Error parsing template: %s

What it means

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.

Source

Thrown at cmd/cryptogen/main.go:425

			os.Exit(-1)
		}
		generatePeerOrg(*outputDir, orgSpec)
	}

	for _, orgSpec := range config.OrdererOrgs {
		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)

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Read the wrapped template error which names the line and issue in the template string.
  2. Balance all {{ }} delimiters and close if/range/with blocks with {{end}}.
  3. Only use fields/functions available to cryptogen templates, e.g. {{.Hostname}}, {{.Domain}}.
  4. If the value is literal text, remove the '{{' characters so it is not treated as a template.

Example fix

// before (yaml)
SANS:
  - "{{.Hostname}.{{.Domain}}"
// after
SANS:
  - "{{.Hostname}}.{{.Domain}}"
Defensive patterns

Strategy: validation

Validate before calling

import ("text/template"; "bytes")
func validTemplate(s string) bool {
    _, err := template.New("probe").Parse(s)
    return err == nil
}
// apply to each templated yaml field before running cryptogen

Prevention

When it happens

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

Common situations: 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.

Related errors


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