hyperledger/fabric · error
Error Unmarshalling YAML
Error message
Error Unmarshalling YAML: %s
What it means
getConfig parses the read YAML data into the Config struct with yaml.Unmarshal. If the content is not valid YAML or does not match the expected schema, this error wraps the YAML parse error. It is a configuration content problem, not an I/O problem.
Solutions
- Read the wrapped YAML error line/column and fix that spot in the file.
- Validate the YAML first (yamllint or a YAML parser) before running cryptogen.
- Replace tabs with spaces and ensure consistent indentation.
- Compare against a known-good crypto-config.yaml from the fabric-samples repo.
Example fix
// before (tabs break YAML) PeerOrgs: - Name: Org1 // after PeerOrgs: - Name: Org1
Defensive patterns
Strategy: validation
Validate before calling
// validate YAML before invoking cryptogen
import "gopkg.in/yaml.v3"
var probe map[string]any
if err := yaml.Unmarshal([]byte(configData), &probe); err != nil {
log.Fatalf("invalid YAML: %v", err)
}
if _, ok := probe["PeerOrgs"]; !ok { log.Fatal("missing PeerOrgs section") } Prevention
- Run yamllint on crypto-config.yaml before use
- Use spaces, never tabs, in YAML
- Start from a known-good sample config and edit minimally
- Check the wrapped line/column in the error to locate the fault
When it happens
Trigger: Running cryptogen generate/extend with a --config file containing malformed YAML (bad indentation, tabs, duplicate keys) or unknown/wrongly-typed fields.
Common situations: Hand-edited crypto-config.yaml with tab characters instead of spaces; missing OrdererOrgs/PeerOrgs sections; wrong types (e.g. Counts as string); YAML copied from docs with smart quotes; Windows line endings.
Related errors
- Error reading configuration
- 1 - Error loading MSP configuration for org
- a collection specified chaincode
- block hashes not maintained in index
- block numbers not maintained in index
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/c6b2bd710b383b9a.
Report an issue: GitHub.
Appendix: source
Thrown at cmd/cryptogen/main.go:274
return nil, fmt.Errorf("Error reading configuration: %s", err)
}
configData = string(data)
} else if *extConfigFile != nil {
data, err := io.ReadAll(*extConfigFile)
if err != nil {
return nil, fmt.Errorf("Error reading configuration: %s", err)
}
configData = string(data)
} else {
configData = defaultConfig
}
config := &Config{}
err := yaml.Unmarshal([]byte(configData), &config)
if err != nil {
return nil, fmt.Errorf("Error Unmarshalling YAML: %s", err)
}
return config, nil
}
func extend() {
config, err := getConfig()
if err != nil {
fmt.Printf("Error reading config: %s", err)
os.Exit(-1)
}
for _, orgSpec := range config.PeerOrgs {
err = renderOrgSpec(&orgSpec, "peer")
if err != nil {
fmt.Printf("Error processing peer configuration: %s", err)
os.Exit(-1)
}View on GitHub (pinned to 2736b63f8f)