hyperledger/fabric · error
error unmarshalling YAML
Error message
error unmarshalling YAML
What it means
GetConfig reads a connection profile and unmarshals it into the NetworkConfig struct using yaml.Unmarshal. This error is wrapped around any YAML parse failure, meaning the file was readable but is not valid YAML or does not match the expected NetworkConfig schema.
Source
Thrown at internal/peer/common/networkconfig.go:172
}
// GetConfig unmarshals the provided connection profile into a network
// configuration struct
func GetConfig(fileName string) (*NetworkConfig, error) {
if fileName == "" {
return nil, errors.New("filename cannot be empty")
}
data, err := os.ReadFile(fileName)
if err != nil {
return nil, errors.Wrap(err, "error reading connection profile")
}
configData := string(data)
config := &NetworkConfig{}
err = yaml.Unmarshal([]byte(configData), &config)
if err != nil {
return nil, errors.Wrap(err, "error unmarshalling YAML")
}
return config, nil
}
View on GitHub (pinned to 2736b63f8f)
Solutions
- Validate the YAML with a linter or `yamllint <file>` to find syntax errors
- Convert tabs to spaces — YAML forbids tab indentation
- Compare against a known-good sample connection profile from test-network fixtures
- Ensure required NetworkConfig fields (organizations, peers, certificateAuthorities) exist with correct nesting
Example fix
// before (invalid: tab indentation) // channels:\n// \tmychannel: ... (tab char in file) // after // channels: // mychannel: ... (spaces only)
Defensive patterns
Strategy: validation
Validate before calling
func validYAML(path string) error {
data, err := os.ReadFile(path)
if err != nil {
return err
}
var v map[string]interface{}
if err := yaml.Unmarshal(data, &v); err != nil {
return fmt.Errorf("invalid YAML in %s: %w", path, err)
}
return nil
} Try / catch
config, err := common.GetConfig(profilePath)
if err != nil {
if strings.Contains(err.Error(), "error unmarshalling YAML") {
log.Fatalf("connection profile %q is not valid YAML: %v", profilePath, err)
}
return err
} Prevention
- Run yamllint on connection profiles before deployment
- Use spaces, never tabs, in YAML files
- Keep profiles generated by Fabric tooling rather than hand-editing them
- Differentiate .yaml vs .json profiles and load each with the right parser
When it happens
Trigger: Calling GetConfig on a file containing invalid YAML syntax (bad indentation, tabs, stray characters), a JSON profile without proper structure, or YAML whose top-level shape does not match NetworkConfig fields.
Common situations: Hand-edited connection profiles with indentation mistakes; saving a JSON connection profile and passing it to a YAML parser path; copy-pasting YAML that introduced tabs; schema mismatch after upgrading Fabric version where profile fields changed.
Related errors
- invalid external builder configuration, path attribute missi
- external builder at path %s has no name attribute
- %s is mandatory and cannot be empty
- refusing to generate block which is missing orderer section
- config ID illegal, cannot be empty
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/3c720bb9aa763d39.
Report an issue: GitHub.