{"record":{"id":"6874ce49c8c95ded","repo":"clockworklabs/SpacetimeDB","slug":"table-schema-should-validate-for-query-builder-cod","errorCode":null,"errorMessage":"table schema should validate for query builder codegen","messagePattern":"table schema should validate for query builder codegen","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/src/unrealcpp.rs","lineNumber":3257,"sourceCode":"            if !(constraints.has_indexed() || constraints.has_unique() || constraints.has_primary_key()) {\n                continue;\n            }\n            let col_idx = columns.iter().next().expect(\"singleton column\").idx();\n            let (field_name, _) = &product_type.elements[col_idx];\n            singleton_indexed_fields.push(field_name.deref().to_case(Case::Pascal));\n        }\n        singleton_indexed_fields\n    };\n\n    for table in iter_tables(module, visibility) {\n        let product_type = module.typespace_for_generate()[table.product_type_ref]\n            .as_product()\n            .expect(\"query builder source should be a product type\");\n        let row_struct = format!(\"F{}Type\", type_ref_name(module_prefix, module, table.product_type_ref));\n        let source_pascal = table.accessor_name.deref().to_case(Case::Pascal);\n        let schema = TableSchema::from_module_def(module, table, (), 0.into())\n            .validated()\n            .expect(\"table schema should validate for query builder codegen\");\n\n        let singleton_indexed_fields = singleton_indexed_fields_for_schema(&schema, product_type);\n\n        let fields = product_type\n            .elements\n            .iter()\n            .map(|(field_name, field_ty)| {\n                (\n                    field_name.deref().to_string(),\n                    field_name.deref().to_case(Case::Pascal),\n                    cpp_ty_fmt_with_module(module_prefix, module, field_ty, module_name).to_string(),\n                    field_ty.clone(),\n                )\n            })\n            .collect::<Vec<_>>();\n\n        source_metas.push(QueryBuilderSourceMeta {\n            row_struct,","sourceCodeStart":3239,"sourceCodeEnd":3275,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/codegen/src/unrealcpp.rs#L3239-L3275","documentation":"Panic in SpacetimeDB's Unreal C++ query-builder code generation. For every table in the module, the generator constructs `TableSchema::from_module_def(module, table, (), 0)` and calls `.validated()`; if the table schema collects validation errors, the `expect` panics and codegen aborts. The invariant assumed is that any table that passed module building must also pass table-schema validation.","triggerScenarios":"Running `spacetime generate` for Unreal C++ bindings where a table definition fails `TableSchema` validation: invalid index/constraint definitions, unsupported column types, or a table auto-injected with a generated row type that the validator rejects. `iter_tables(module, visibility)` feeds each table, so any single bad table kills the whole run.","commonSituations":"Version skew between the module SDK used to build the module and the CLI generating bindings; introducing a table with a newly supported type that older codegen validators reject; corrupted or hand-modified module description files; constraint/index syntax that changed between releases.","solutions":["Build/validate the module first and read the real validation errors (`spacetime build`) instead of relying on the codegen panic message.","Bisect your module: comment out recently added tables and re-run codegen until the failing table is identified, then fix its definition.","Align versions: upgrade the `spacetime` CLI and the module's `spacetimedb-std` dependency to the same release.","Report upstream if a table that builds cleanly still panics here — that is a codegen invariant break, not a user error."],"exampleFix":"// before: table whose schema fails validation (e.g. indexed unique on unsupported type)\ntable Player { name: String #[primary_key], payload: Bytes #[index] }\n\n// after: index a supported, comparable type\ntable Player { name: String #[primary_key], score: u64 #[index] }","handlingStrategy":"validation","validationCode":"for table in iter_tables(module, visibility) {\n    let schema = TableSchema::from_module_def(module, table, (), 0.into());\n    if !schema.validated() { /* surface errors, skip codegen */ }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate table schemas before invoking binding generation.","Treat 'builds but fails codegen validation' as an upstream bug: pin the working CLI version and report it.","Keep table definitions to types documented as supported for C++ bindings."],"tags":["rust","spacetimedb","codegen","query-builder","unreal","schema","validation","panic"],"backgroundTag":"schema-validation-failed","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}