{"record":{"id":"36a1533fe8e54fd2","repo":"hyperledger/fabric","slug":"error-unmarshalling-yaml-file-s-s","errorCode":null,"errorMessage":"error unmarshalling YAML file %s: %s","messagePattern":"error unmarshalling YAML file (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/common/config.go","lineNumber":34,"sourceCode":")\n\n// Config aggregates configuration of TLS and signing\ntype Config struct {\n\tVersion      int\n\tTLSConfig    comm.Config\n\tSignerConfig signer.Config\n}\n\n// ConfigFromFile loads the given file and converts it to a Config\nfunc ConfigFromFile(file string) (Config, error) {\n\tconfigData, err := os.ReadFile(file)\n\tif err != nil {\n\t\treturn Config{}, errors.WithStack(err)\n\t}\n\tconfig := Config{}\n\n\tif err := yaml.Unmarshal(configData, &config); err != nil {\n\t\treturn Config{}, errors.Errorf(\"error unmarshalling YAML file %s: %s\", file, err)\n\t}\n\n\treturn config, validateConfig(config)\n}\n\n// ToFile writes the config into a file\nfunc (c Config) ToFile(file string) error {\n\tif err := validateConfig(c); err != nil {\n\t\treturn errors.Wrap(err, \"config isn't valid\")\n\t}\n\tb, err := yaml.Marshal(c)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"failed to marshal config\")\n\t}\n\tif err := os.WriteFile(file, b, 0o600); err != nil {\n\t\treturn errors.Errorf(\"failed writing file %s: %v\", file, err)\n\t}\n\treturn nil","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/cmd/common/config.go#L16-L52","documentation":"batchUpdateDocuments() parses the CouchDB instance URL with url.Parse to build the _bulk_docs URL. If the configured URL is malformed, url.Parse fails and the error is wrapped as 'error parsing CouchDB URL: <url>'; the entire batch write of documents is aborted before any HTTP request is sent.","triggerScenarios":"A batched write (from state commits or checkpoints) where couchInstance.url() is malformed — bad couchDBAddress in core.yaml, unresolved env placeholders, illegal characters/whitespace in the host portion.","commonSituations":"Peer config mistakes (typo, trailing space, missing host), broken env substitution in containerized deployments, IPv6 address without brackets after a config edit.","solutions":["Fix ledger.state.couchDBConfig.couchDBAddress to a valid host:port","Resolve CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS env overrides correctly","Bracket IPv6 literals: [::1]:5984","Print dbclient.couchInstance.url() and validate with url.Parse to see the exact parse failure","Validate peer core.yaml (and any config overlays) after edits before restarting"],"exampleFix":"// before\ncouchDBAddress: couchdb: 5984   # space breaks parsing\n// after\ncouchDBAddress: couchdb:5984","handlingStrategy":"validation","validationCode":"u, err := url.Parse(couchAddress)\nif err != nil || u.Host == \"\" {\n    return fmt.Errorf(\"invalid couchDBAddress %q: %v\", couchAddress, err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"error parsing CouchDB URL\") {\n    return fmt.Errorf(\"peer couchDBAddress invalid, no docs written: %w\", err)\n}","preventionTips":["Validate the address at startup so writes never reach a broken config","Use bare host:port; never include scheme or whitespace","Bracket IPv6 literals explicitly","Automate config linting in CI for core.yaml changes","Confirm env substitutions resolve in every deployment environment"],"tags":["couchdb","url","configuration","fabric"],"backgroundTag":"invalid-couchdb-url","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"}