{"record":{"id":"1aa956bc00c3a878","repo":"clockworklabs/SpacetimeDB","slug":"type-error-module-cleared-and-replaced-with-err","errorCode":null,"errorMessage":"\n[TYPE ERROR] Module cleared and replaced with error type: %s\n","messagePattern":"\n\\[TYPE 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":347,"sourceCode":"        } else {\n            error_type_name = \"ERROR_TYPE_REGISTRATION_FAILED\";\n        }\n        \n        // Add a single named type export that points to a non-existent typespace index\n        // This will cause SpacetimeDB to error when it tries to resolve the type\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; // Invalid typespace index - will cause an error\n        error_type.custom_ordering = false;\n        \n        getV10Builder().GetTypeDefs().push_back(error_type);\n        \n        // Don't add anything to the typespace - this ensures the reference is invalid\n        // The server will fail with an error message that includes our error type name\n        \n        // Also log to stderr for debugging\n        fprintf(stderr, \"\\n[TYPE ERROR] Module cleared and replaced with error type: %s\\n\", error_type_name.c_str());\n        fprintf(stderr, \"Original error: %s\\n\\n\", error.c_str());\n        fflush(stderr);\n    }\n    //#define DEBUG_TYPE_REGISTRATION\n    // Type validation passed - log statistics only in debug mode\n    #ifdef DEBUG_TYPE_REGISTRATION\n    else {\n        fprintf(stderr, \"[Type Validation] OK - %zu types, %zu tables, %zu reducers\\n\",\n                getV10Builder().GetTypespace().types.size(),\n                getV10Builder().GetTables().size(),\n                getV10Builder().GetReducers().size());\n    }\n    #endif\n}\n\n\nstd::vector<uint8_t> Internal::Module::SerializeModuleDef() {\n    RawModuleDefV10 v10_module = getV10Builder().BuildModuleDef();","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-cpp/src/internal/Module.cpp#L329-L365","documentation":"Banner printed by __preinit__99_validate_types when ModuleTypeRegistration reports hasError(). The module is cleared and replaced by an error type embedding the message (e.g. ERROR_RECURSIVE_TYPE_REFERENCE_<name>) at invalid typespace index 999999; the server then fails module description resolution. Known error messages feeding this path are 'Recursive type reference detected: <type> is referencing itself' and 'Missing type name for complex type...' (toolchain without demangling support, or an anonymous/nested type with no name).","triggerScenarios":"A type re-entering registerType while still being registered (types_being_registered_ cycle detection fires); a complex type (e.g. a nested struct used as a column) whose name cannot be determined because typeid-based demangling is unavailable or the type is anonymous.","commonSituations":"Using unnamed/anonymous structs or lambdas-captured types as table columns; building with a toolchain where typeid(...).name() is mangled and demangling support is off; recursive types that evade the earlier g_circular_ref_error path.","solutions":["Read the 'Original error:' line printed right after the banner - it contains the exact registration error and type name","For 'Recursive type reference' - break the cycle by referencing rows by id or using indirection","For 'Missing type name' - give the complex type a concrete named struct and register it explicitly (registerTypeByName / explicit type-name macro) instead of relying on demangling","Verify you are on a supported toolchain where type-name demangling is enabled"],"exampleFix":"// before\nstruct Item {\n  std::vector<Item> children; // recursive -> 'Recursive type reference'\n};\n\n// after\nstruct Item {\n  std::vector<uint64_t> child_ids;\n};","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give every complex column type a named struct; avoid anonymous/nested types","Use a toolchain with type-name demangling enabled","Run a describe-module smoke test asserting no type name starts with ERROR_"],"tags":["spacetimedb","cpp","types","module-init","registration"],"backgroundTag":"type-registration-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"}