{"record":{"id":"f0007a1a31035b13","repo":"hyperledger/fabric","slug":"error-parsing-couchdb-url-s","errorCode":null,"errorMessage":"error parsing CouchDB URL: %s","messagePattern":"error parsing CouchDB URL: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go","lineNumber":842,"sourceCode":"\n\tcouchDoc.attachments = attachments\n\treturn &couchDoc, revision, nil\n}\n\n// readDocRange method provides function to a range of documents based on the start and end keys\n// startKey and endKey can also be empty strings.  If startKey and endKey are empty, all documents are returned\n// This function provides a limit option to specify the max number of entries and is supplied by config.\n// Skip is reserved for possible future use.\nfunc (dbclient *couchDatabase) readDocRange(startKey, endKey string, limit int32) ([]*queryResult, string, error) {\n\tdbName := dbclient.dbName\n\tcouchdbLogger.Debugf(\"[%s] Entering ReadDocRange()  startKey=%s, endKey=%s\", dbName, startKey, endKey)\n\n\tvar results []*queryResult\n\n\trangeURL, err := url.Parse(dbclient.couchInstance.url())\n\tif err != nil {\n\t\tcouchdbLogger.Errorf(\"URL parse error: %s\", err)\n\t\treturn nil, \"\", errors.Wrapf(err, \"error parsing CouchDB URL: %s\", dbclient.couchInstance.url())\n\t}\n\n\tqueryParms := rangeURL.Query()\n\t// Increment the limit by 1 to see if there are more qualifying records\n\tqueryParms.Set(\"limit\", strconv.FormatInt(int64(limit+1), 10))\n\tqueryParms.Add(\"include_docs\", \"true\")\n\tqueryParms.Add(\"inclusive_end\", \"false\") // endkey should be exclusive to be consistent with goleveldb\n\tqueryParms.Add(\"attachments\", \"true\")    // get the attachments as well\n\n\t// Append the startKey if provided\n\tif startKey != \"\" {\n\t\tif startKey, err = encodeForJSON(startKey); err != nil {\n\t\t\treturn nil, \"\", err\n\t\t}\n\t\tqueryParms.Add(\"startkey\", \"\\\"\"+startKey+\"\\\"\")\n\t}\n\n\t// Append the endKey if provided","sourceCodeStart":824,"sourceCodeEnd":860,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go#L824-L860","documentation":"This error is returned by CouchDatabase range query handling when url.Parse fails on the CouchDB instance URL (dbclient.couchInstance.url()). The library parses the instance URL to attach query parameters (limit, include_docs) before issuing the HTTP range request. A malformed URL string makes parsing impossible, so the request is aborted and the underlying net/url error is wrapped with the offending URL text.","triggerScenarios":"Calling RangeScan/ReadRange-related APIs on a CouchDatabase whose couchInstance was constructed with an unparseable URL, e.g. 'error parsing CouchDB URL: http://[::1' or a URL containing spaces/control characters.","commonSituations":"Ledger config (core.yaml couchDBConfig address) containing stray characters, IPv6 literals without brackets, protocol typos like 'http:/host:5984', or environment-substituted values that inject whitespace or newlines into the address.","solutions":["Inspect the wrapped message to see the offending URL string and fix the couchDBConfig address in core.yaml (protocol + host + port).","Validate the URL with url.Parse (or net.JoinHostPort for IPv6 hosts) before starting the peer.","Check environment variable substitutions for stray spaces/newlines in COUCHDB_ADDRESS.","Recreate the CouchInstance via CreateCouchInstance so the connection definition is re-parsed after fixing config."],"exampleFix":"// before (core.yaml)\npeer:\n  ledger:\n    state:\n      stateDatabase: CouchDB\n      couchDBConfig:\n        address: http:/couchdb:5984\n// after\npeer:\n  ledger:\n    state:\n      stateDatabase: CouchDB\n      couchDBConfig:\n        address: couchdb:5984","handlingStrategy":"validation","validationCode":"if _, err := url.Parse(couchAddr); err != nil {\n    return fmt.Errorf(\"invalid couchDBConfig address %q: %w\", couchAddr, err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate couchDBConfig.address with url.Parse at peer startup","Use net.JoinHostPort when building addresses for IPv6 hosts","Quote env-var substitutions to avoid trailing whitespace","Keep scheme handling consistent (fabric adds scheme itself; do not double-prefix)"],"tags":["couchdb","url-parsing","configuration"],"backgroundTag":"invalid-url-format","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"}