{"record":{"id":"6c94273e412a1418","repo":"clockworklabs/SpacetimeDB","slug":"uint8array-is-not-32-bytes-long-array","errorCode":null,"errorMessage":"Uint8Array is not 32 bytes long: [${array}]","messagePattern":"Uint8Array is not 32 bytes long: \\[(.+?)\\]","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/lib/util.ts","lineNumber":55,"sourceCode":"  return true;\n}\n\nexport function uint8ArrayToHexString(array: Uint8Array): string {\n  return Array.prototype.map\n    .call(array.reverse(), x => ('00' + x.toString(16)).slice(-2))\n    .join('');\n}\n\nexport function uint8ArrayToU128(array: Uint8Array): bigint {\n  if (array.length != 16) {\n    throw new Error(`Uint8Array is not 16 bytes long: ${array}`);\n  }\n  return new BinaryReader(array).readU128();\n}\n\nexport function uint8ArrayToU256(array: Uint8Array): bigint {\n  if (array.length != 32) {\n    throw new Error(`Uint8Array is not 32 bytes long: [${array}]`);\n  }\n  return new BinaryReader(array).readU256();\n}\n\nexport function hexStringToUint8Array(str: string): Uint8Array {\n  if (str.startsWith('0x')) {\n    str = str.slice(2);\n  }\n  const matches = str.match(/.{1,2}/g) || [];\n  const data = Uint8Array.from(\n    matches.map((byte: string) => parseInt(byte, 16))\n  );\n  return data.reverse();\n}\n\nexport function hexStringToU128(str: string): bigint {\n  return uint8ArrayToU128(hexStringToUint8Array(str));\n}","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-typescript/src/lib/util.ts#L37-L73","documentation":"#[spacetimedb::table] derives the SATS type via sats_type_from_derive and then requires SatsTypeData::Product — only structs can be tables, because a table needs a fixed set of columns. Enums and unions produce Sum data, so the derive bails with a call-site span.","triggerScenarios":"Annotating an enum or union with #[spacetimedb::table(...)] — the else-branch on the SatsTypeData match fires.","commonSituations":"Trying to make a tagged-union table; a struct converted to an enum while the table attribute stayed; misunderstanding that tables are row types, not variant types.","solutions":["Make the item a struct with one field per column.","For variant values without table semantics, use #[derive(SpacetimeType)] on the enum and reference it as a column type in a struct table.","If variants must be queryable, model them as rows with a discriminator column."],"exampleFix":"// before\n#[spacetimedb::table(accessor = shape)]\nenum Shape { Circle { r: f64 }, Square { a: f64 } }\n\n// after\n#[derive(SpacetimeType)]\nenum Shape { Circle { r: f64 }, Square { a: f64 } }\n\n#[spacetimedb::table(accessor = shape)]\nstruct ShapeRow { #[auto_inc] id: u64, shape: Shape }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only apply #[spacetimedb::table] to structs; use plain SpacetimeType derives for enums/unions.","When converting a table struct into another kind of item, remove the table attribute in the same commit."],"tags":["spacetimedb","proc-macro","table","struct","compile-time"],"backgroundTag":"unsupported-derive-target","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}