{"record":{"id":"3c720bb9aa763d39","repo":"hyperledger/fabric","slug":"error-unmarshalling-yaml","errorCode":null,"errorMessage":"error unmarshalling YAML","messagePattern":"error unmarshalling YAML","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/common/networkconfig.go","lineNumber":172,"sourceCode":"}\n\n// GetConfig unmarshals the provided connection profile into a network\n// configuration struct\nfunc GetConfig(fileName string) (*NetworkConfig, error) {\n\tif fileName == \"\" {\n\t\treturn nil, errors.New(\"filename cannot be empty\")\n\t}\n\n\tdata, err := os.ReadFile(fileName)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"error reading connection profile\")\n\t}\n\n\tconfigData := string(data)\n\tconfig := &NetworkConfig{}\n\terr = yaml.Unmarshal([]byte(configData), &config)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"error unmarshalling YAML\")\n\t}\n\n\treturn config, nil\n}\n","sourceCodeStart":154,"sourceCodeEnd":177,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/common/networkconfig.go#L154-L177","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (invalid: tab indentation)\n// channels:\\n// \\tmychannel: ... (tab char in file)\n// after\n// channels:\n//   mychannel: ...  (spaces only)","handlingStrategy":"validation","validationCode":"func validYAML(path string) error {\n    data, err := os.ReadFile(path)\n    if err != nil {\n        return err\n    }\n    var v map[string]interface{}\n    if err := yaml.Unmarshal(data, &v); err != nil {\n        return fmt.Errorf(\"invalid YAML in %s: %w\", path, err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"config, err := common.GetConfig(profilePath)\nif err != nil {\n    if strings.Contains(err.Error(), \"error unmarshalling YAML\") {\n        log.Fatalf(\"connection profile %q is not valid YAML: %v\", profilePath, err)\n    }\n    return err\n}","preventionTips":["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"],"tags":["fabric","config","yaml"],"backgroundTag":"yaml-parse-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"}