{"record":{"id":"d173146d96d1bb27","repo":"hyperledger/fabric","slug":"database-name-is-illegal-cannot-be-empty","errorCode":null,"errorMessage":"database name is illegal, cannot be empty","messagePattern":"database name is illegal, cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdbutil.go","lineNumber":281,"sourceCode":"\t\treturn chainName + \"_\" + escapedNamespace + \"(\" + hashOfNamespaceDBName + \")\"\n\t}\n\treturn namespaceDBName\n}\n\n// mapAndValidateDatabaseName checks to see if the database name contains illegal characters\n// CouchDB Rules: Only lowercase characters (a-z), digits (0-9), and any of the characters\n// _, $, (, ), +, -, and / are allowed. Must begin with a letter.\n//\n// Restrictions have already been applied to the database name from Orderer based on\n// restrictions required by Kafka and couchDB (except a '.' char). The databaseName\n// passed in here is expected to follow `[a-z][a-z0-9.$_()+-]*` pattern.\n//\n// This validation will simply check whether the database name matches the above pattern and will replace\n// all occurrence of '.' by '$'. This will not cause collisions in the transformed named\nfunc mapAndValidateDatabaseName(databaseName string) (string, error) {\n\t// test Length\n\tif len(databaseName) <= 0 {\n\t\treturn \"\", errors.Errorf(\"database name is illegal, cannot be empty\")\n\t}\n\tif len(databaseName) > maxLength {\n\t\treturn \"\", errors.Errorf(\"database name is illegal, cannot be longer than %d\", maxLength)\n\t}\n\tre, err := regexp.Compile(expectedDatabaseNamePattern)\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"error compiling regexp: %s\", expectedDatabaseNamePattern)\n\t}\n\tmatched := re.FindString(databaseName)\n\tif len(matched) != len(databaseName) {\n\t\treturn \"\", errors.Errorf(\"databaseName '%s' does not match pattern '%s'\", databaseName, expectedDatabaseNamePattern)\n\t}\n\t// replace all '.' to '$'. The databaseName passed in will never contain an '$'.\n\t// So, this translation will not cause collisions\n\tdatabaseName = strings.Replace(databaseName, \".\", \"$\", -1)\n\treturn databaseName, nil\n}\n","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdbutil.go#L263-L299","documentation":"mapAndValidateDatabaseName rejects an empty database name string before applying mapping rules. CouchDB database names must be non-empty; the statecouchdb layer validates length and character constraints up-front. This error means the caller passed a zero-length name.","triggerScenarios":"createCouchDatabase (and tests) invoked with a databaseName of \"\", typically from an empty channel name or empty namespace-derived name passed to CreateCouchDatabase/CreateSystemDatabase.","commonSituations":"Misconfigured channel or ledger ID; a caller constructing database names from an unset variable; bug in namespace-to-databasename mapping producing empty output.","solutions":["Ensure the channel name / ledger ID used to derive the database name is set and non-empty before opening the ledger.","Check the peer configuration for an empty ledger or chaincode identifier.","Trace the caller (createCouchDatabase) to see where the empty string originates and fix the name derivation."],"exampleFix":"// before\nif namespace == \"\" { db, _ := createCouchDatabase(couchInstance, namespace) }\n// after\nif namespace == \"\" { return errors.New(\"namespace must be non-empty\") }\ndb, err := createCouchDatabase(couchInstance, namespace)","handlingStrategy":"validation","validationCode":"func validateDBName(name string) error {\n    if name == \"\" { return errors.New(\"database name must not be empty\") }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"cannot be empty\") {\n        // the channel/ledger id used to derive the name was empty; fix the source\n    }\n    return err\n}","preventionTips":["Ensure channel names and chaincode names are set and non-empty.","Validate identifiers before constructing database names.","Check configuration for unset variables that feed name derivation."],"tags":["couchdb","validation","database-name"],"backgroundTag":"invalid-database-name","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"}