clockworklabs/SpacetimeDB · error · Error

Cannot extract accessor name from query

Error message

Cannot extract accessor name from query

What it means

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.

Source

Thrown at crates/bindings-typescript/src/lib/query.ts:1056

/**
 * Extract the table name from a query builder expression.
 */
export function getQueryTableName(query: any): string {
  if (query.table) return query.table.name; // FromBuilder
  if (query.name) return query.name; // TableRefImpl
  if (query.sourceQuery) return query.sourceQuery.table.name; // SemijoinImpl (source table)
  throw new Error('Cannot extract table name from query');
}

/**
 * Extract the accessor name from a query builder expression.
 */
export function getQueryAccessorName(query: any): string {
  if (query.table) return query.table.accessorName; // FromBuilder
  if (query.accessorName) return query.accessorName; // TableRefImpl
  if (query.sourceQuery) return query.sourceQuery.table.accessorName; // SemijoinImpl
  throw new Error('Cannot extract accessor name from query');
}

/**
 * Extract the BooleanExpr from a query builder, if any.
 */
export function getQueryWhereClause(query: any): BooleanExpr<any> | undefined {
  if (query.whereClause) return query.whereClause; // FromBuilder
  return undefined; // TableRefImpl has no where clause
}

// TODO: Fix this.
function _createIndexedRowExpr<TableDef extends TypedTableDef>(
  tableDef: TableDef,
  cols: RowExpr<TableDef>
): IndexedRowExpr<TableDef> {
  const indexed = new Set<ColumnNames<TableDef>>();
  for (const idx of tableDef.indexes) {
    if ('columns' in idx) {

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Pass the actual table expression: useTable(tables.user) or useTable(tables.user.where(r => r.online.eq(true)))
  2. If wrapping the hooks, forward the builder unchanged and only add callbacks
  3. Teach the wrapper to reject non-builders early with a clearer message

Example fix

// before
const [rows] = useTable({ table: 'user' } as any); // plain object -> throws

// after
const [rows] = useTable(tables.user);
Defensive patterns

Strategy: type-guard

Validate before calling

function isKnownQueryBuilder(q: unknown): boolean {
  const c = q as Record<string, unknown> | null | undefined;
  return Boolean(c && (c.table || c.accessorName || c.sourceQuery));
}

Type guard

type KnownQueryBuilder = { table: unknown } | { accessorName: unknown } | { sourceQuery: unknown };
function isKnownQueryBuilder(q: unknown): q is KnownQueryBuilder {
  const c = q as Record<string, unknown> | null | undefined;
  return Boolean(c && (c.table || c.accessorName || c.sourceQuery));
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/ee4cbdb4481ab5b7. Report an issue: GitHub.