{"record":{"id":"37b112102bd3da9b","repo":"hyperledger/fabric","slug":"error-compiling-regexp-s","errorCode":null,"errorMessage":"error compiling regexp: %s","messagePattern":"error compiling regexp: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdbutil.go","lineNumber":288,"sourceCode":"// _, $, (, ), +, -, 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\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}","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdbutil.go#L270-L306","documentation":"This wraps a regexp.Compile failure of the constant expectedDatabaseNamePattern used to validate CouchDB database names. Since the pattern is a compile-time constant in the library, this error should be impossible in normal operation; it only occurs if the pattern constant is edited to an invalid regex (e.g. during customization).","triggerScenarios":"regexp.Compile(expectedDatabaseNamePattern) returns an error — only possible when the source constant expectedDatabaseNamePattern has been modified to a syntactically invalid regular expression.","commonSituations":"Developers patching Fabric source to relax database-name rules and introducing a malformed regex; vendored/patched builds.","solutions":["Revert or correct the expectedDatabaseNamePattern constant in couchdbutil.go to a valid regular expression.","Test the regex at regex101.com or in a Go scratch program before committing the change.","Rebuild the peer from unmodified upstream source to eliminate the customization."],"exampleFix":"// before (invalid pattern)\nconst expectedDatabaseNamePattern = \"^[a-z][a-z0-9-$()_+]*[$(\" \n// after\nconst expectedDatabaseNamePattern = \"^[a-z][a-z0-9-$()_+]*$\"","handlingStrategy":"try-catch","validationCode":"// sanity-check any custom pattern before building\nif _, err := regexp.Compile(expectedDatabaseNamePattern); err != nil { panic(\"invalid db name pattern\") }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"error compiling regexp\") {\n        // pattern constant was customized incorrectly; revert to upstream\n    }\n    return err\n}","preventionTips":["Do not modify expectedDatabaseNamePattern without testing the regex.","Validate regex changes with a unit test before building the peer.","Build from unmodified upstream source when possible."],"tags":["couchdb","regex","validation","internal"],"backgroundTag":"invalid-regex","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"}