{"record":{"id":"784adb77538341a3","repo":"clockworklabs/SpacetimeDB","slug":"constraint-registration-error-module-cleared-an","errorCode":null,"errorMessage":"\n[CONSTRAINT REGISTRATION ERROR] Module cleared and replaced with error type: %s\n","messagePattern":"\n\\[CONSTRAINT REGISTRATION ERROR\\] Module cleared and replaced with error type: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bindings-cpp/src/internal/Module.cpp","lineNumber":286,"sourceCode":"\n    if (g_constraint_registration_error) {\n        getV10Builder().Clear();\n\n        std::string error_type_name = \"ERROR_CONSTRAINT_REGISTRATION_\" + g_constraint_registration_error_code;\n        for (char& c : error_type_name) {\n            if (!std::isalnum(c) && c != '_') {\n                c = '_';\n            }\n        }\n\n        RawTypeDefV10 error_type;\n        error_type.source_name.scope = {};\n        error_type.source_name.source_name = error_type_name;\n        error_type.ty = 999999;\n        error_type.custom_ordering = false;\n        getV10Builder().GetTypeDefs().push_back(error_type);\n\n        fprintf(stderr, \"\\n[CONSTRAINT REGISTRATION ERROR] Module cleared and replaced with error type: %s\\n\", error_type_name.c_str());\n        fprintf(stderr, \"Original error: %s\\n\\n\", g_constraint_registration_error_details.c_str());\n        fflush(stderr);\n        return;\n    }\n    \n    // Check if any errors occurred during type registration\n    auto& type_reg = getModuleTypeRegistration();\n    if (type_reg.hasError()) {\n        // Type registration detected an error - create a special error module\n        const std::string& error = type_reg.getErrorMessage();\n        \n        // Clear the module state to start fresh.\n        getV10Builder().Clear();\n        \n        // Create an error type name that embeds the error message and type structure\n        std::string error_type_name;\n        if (error.find(\"Recursive type reference\") != std::string::npos) {\n            // Extract the type name from the error message","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-cpp/src/internal/Module.cpp#L268-L304","documentation":"Banner printed by __preinit__99_validate_types when g_constraint_registration_error is set. The module is cleared and replaced by error type ERROR_CONSTRAINT_REGISTRATION_<code> (code sanitized to [A-Za-z0-9_]) at invalid typespace index 999999, so the server fails to resolve the module description; the banner names the generated error type so you can correlate it with the publish failure.","triggerScenarios":"Any SetConstraintRegistrationError code raised by V10Builder: FIELD_NOT_FOUND, TABLE_NOT_FOUND, NO_FIELD_DESCRIPTORS, TABLE_NO_FIELD_DESCRIPTORS, MULTI_INDEX_EMPTY, DEFAULT_ON_PRIMARY_KEY, duplicate constraint/index names, etc.","commonSituations":"Field renamed without updating constraint macros; constraint macros compiled before the table registration; empty multi-column index argument lists; schema refactors across translation units.","solutions":["Match the ERROR_CONSTRAINT_REGISTRATION_<code> name from this banner to the codes in v10_builder.h to identify the exact check that failed","Read the 'Original error:' line printed right after it (error 669) - it carries table/field/index names","Fix the named macro (field name typo, ordering, empty index list) and republish"],"exampleFix":"// before\nINDEX_MULTI(MyTable, my_index, ); // empty field list -> MULTI_INDEX_EMPTY\n\n// after\nINDEX_MULTI(MyTable, my_index, owner_id, created_at);","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cross-reference the ERROR_CONSTRAINT_REGISTRATION_<code> name with the codes documented in v10_builder.h","Treat any publish failure mentioning ERROR_* types as a schema bug and check module stderr for the banner","Keep constraint macros in the same TU as the table registration"],"tags":["spacetimedb","cpp","schema","constraints","module-init"],"backgroundTag":"schema-constraint-validation-failed","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}