{"record":{"id":"ee4cbdb4481ab5b7","repo":"clockworklabs/SpacetimeDB","slug":"cannot-extract-accessor-name-from-query","errorCode":null,"errorMessage":"Cannot extract accessor name from query","messagePattern":"Cannot extract accessor name from query","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/lib/query.ts","lineNumber":1056,"sourceCode":"\n/**\n * Extract the table name from a query builder expression.\n */\nexport function getQueryTableName(query: any): string {\n  if (query.table) return query.table.name; // FromBuilder\n  if (query.name) return query.name; // TableRefImpl\n  if (query.sourceQuery) return query.sourceQuery.table.name; // SemijoinImpl (source table)\n  throw new Error('Cannot extract table name from query');\n}\n\n/**\n * Extract the accessor name from a query builder expression.\n */\nexport function getQueryAccessorName(query: any): string {\n  if (query.table) return query.table.accessorName; // FromBuilder\n  if (query.accessorName) return query.accessorName; // TableRefImpl\n  if (query.sourceQuery) return query.sourceQuery.table.accessorName; // SemijoinImpl\n  throw new Error('Cannot extract accessor name from query');\n}\n\n/**\n * Extract the BooleanExpr from a query builder, if any.\n */\nexport function getQueryWhereClause(query: any): BooleanExpr<any> | undefined {\n  if (query.whereClause) return query.whereClause; // FromBuilder\n  return undefined; // TableRefImpl has no where clause\n}\n\n// TODO: Fix this.\nfunction _createIndexedRowExpr<TableDef extends TypedTableDef>(\n  tableDef: TableDef,\n  cols: RowExpr<TableDef>\n): IndexedRowExpr<TableDef> {\n  const indexed = new Set<ColumnNames<TableDef>>();\n  for (const idx of tableDef.indexes) {\n    if ('columns' in idx) {","sourceCodeStart":1038,"sourceCodeEnd":1074,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-typescript/src/lib/query.ts#L1038-L1074","documentation":"getQueryAccessorName(query) duck-types the same three builder shapes as getQueryTableName (FromBuilder .table.accessorName, TableRefImpl .accessorName, SemijoinImpl .sourceQuery.table.accessorName) and throws when none match. It runs inside the framework hooks - React useTable, Vue/Svelte/Solid useTable, Angular injectTable, and the TanStack SpacetimeDBQueryClient - so a bad argument surfaces as this error during hook setup.","triggerScenarios":"Calling useTable(query)/injectTable(query)/TanStack query helpers with a plain object, a mocked builder, or a built Query instead of a real table reference, .where(...) chain, or semijoin builder.","commonSituations":"Wrapping the hooks in custom layers that forward the wrong object; test mocks replacing builders; passing { table: 'user' } style literals that only look like a builder.","solutions":["Pass the actual table expression: useTable(tables.user) or useTable(tables.user.where(r => r.online.eq(true)))","If wrapping the hooks, forward the builder unchanged and only add callbacks","Teach the wrapper to reject non-builders early with a clearer message"],"exampleFix":"// before\nconst [rows] = useTable({ table: 'user' } as any); // plain object -> throws\n\n// after\nconst [rows] = useTable(tables.user);","handlingStrategy":"type-guard","validationCode":"function isKnownQueryBuilder(q: unknown): boolean {\n  const c = q as Record<string, unknown> | null | undefined;\n  return Boolean(c && (c.table || c.accessorName || c.sourceQuery));\n}","typeGuard":"type KnownQueryBuilder = { table: unknown } | { accessorName: unknown } | { sourceQuery: unknown };\nfunction isKnownQueryBuilder(q: unknown): q is KnownQueryBuilder {\n  const c = q as Record<string, unknown> | null | undefined;\n  return Boolean(c && (c.table || c.accessorName || c.sourceQuery));\n}","tryCatchPattern":null,"preventionTips":["Call useTable/injectTable/TanStack helpers with the real table builder from your generated tables object","Forward builder arguments unchanged inside custom hook wrappers","Reject non-builder inputs in wrappers with a descriptive error before the library does"],"tags":["query-builder","react","vue","svelte","hooks","spacetimedb"],"backgroundTag":"unrecognized-query-shape","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}