{"record":{"id":"04aa4ab9dece87de","repo":"hyperledger/fabric","slug":"databasename-s-does-not-match-pattern-s","errorCode":null,"errorMessage":"databaseName '%s' does not match pattern '%s'","messagePattern":"databaseName '(.+?)' does not match pattern '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdbutil.go","lineNumber":292,"sourceCode":"// 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\n// escapeUpperCase replaces every upper case letter with a '$' and the respective\n// lower-case letter\nfunc escapeUpperCase(dbName string) string {\n\tre := regexp.MustCompile(`([A-Z])`)\n\tdbName = re.ReplaceAllString(dbName, \"$$\"+\"$1\")\n\treturn strings.ToLower(dbName)\n}\n\n// DropApplicationDBs drops all application databases.\nfunc DropApplicationDBs(config *ledger.CouchDBConfig) error {\n\tcouchdbLogger.Info(\"Dropping CouchDB application databases ...\")","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdbutil.go#L274-L310","documentation":"mapAndValidateDatabaseName matches the provided name against expectedDatabaseNamePattern and requires the whole string to match. If the pattern match length differs from the input length, the name contains characters CouchDB forbids (uppercase, spaces, slashes, etc.) and cannot be safely mapped. Note the library first maps '.' to '$' in callers, so this error means invalid characters remain.","triggerScenarios":"createCouchDatabase with a databaseName containing characters outside [a-z0-9-$()_+] or starting with a non-letter, e.g. channel names with uppercase letters, underscores at the start, or spaces.","commonSituations":"Channels or chaincode names created with uppercase characters (Fabric normally rejects these upstream); external code calling the CouchDB layer directly with un-sanitized names; database names from legacy data that violate the newer pattern.","solutions":["Use lowercase alphanumeric channel and chaincode names so the derived database name matches the pattern.","If calling the API directly, sanitize the name first (lowercase, strip disallowed characters, replace '.' with '$').","Check where the name originates (channel ID / namespace) and fix the source identifier."],"exampleFix":"// before\ndb, err := createCouchDatabase(couchInstance, \"My Channel\")\n// after\nname := strings.ToLower(strings.ReplaceAll(\"My Channel\", \" \", \"\"))\ndb, err := createCouchDatabase(couchInstance, name)","handlingStrategy":"validation","validationCode":"const pattern = `^[a-z][a-z0-9-$()_+]*$`\nvar re = regexp.MustCompile(pattern)\nfunc validDBName(name string) bool { m := re.FindString(name); return len(m) == len(name) }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"does not match pattern\") {\n        // lowercase/sanitize the name or fix the channel/chaincode identifier\n    }\n    return err\n}","preventionTips":["Use only lowercase alphanumerics, '-', '$', '(', ')', '_', '+' in names.","Never create channels with uppercase characters or spaces.","Sanitize names before calling createCouchDatabase directly."],"tags":["couchdb","validation","database-name","naming"],"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"}