toeverything/AFFiNE · error · BlockSuiteError

DatabaseBlockError

DatabaseBlockError

Error message

can't resolve ref type

What it means

firstFilterName() resolves the type of a VariableRef via getRefType(). If the referenced variable's type cannot be resolved (returns null), it throws DatabaseBlockError. The filter system needs a concrete type to find a matching filter function.

Source

Thrown at blocksuite/affine/data-view/src/core/filter/utils.ts:11

import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';

import { getRefType } from '../expression/ref/ref.js';
import type { Variable, VariableRef } from '../expression/types.js';
import { filterMatcher } from './filter-fn/matcher.js';
import type { FilterGroup, SingleFilter } from './types.js';

export const firstFilterName = (vars: Variable[], ref: VariableRef) => {
  const type = getRefType(vars, ref);
  if (!type) {
    throw new BlockSuiteError(
      ErrorCode.DatabaseBlockError,
      `can't resolve ref type`
    );
  }
  return filterMatcher.firstMatchedBySelfType(type)?.name;
};
export const firstFilterByRef = (
  vars: Variable[],
  ref: VariableRef
): SingleFilter => {
  return {
    type: 'filter',
    left: ref,
    function: firstFilterName(vars, ref),
    args: [],
  };
};
export const firstFilter = (vars: Variable[]): SingleFilter => {

View on GitHub (pinned to 26c515e050)

Solutions

  1. Ensure the referenced variable has a registered, resolvable type before constructing a filter.
  2. Re-resolve or migrate filter refs after column type changes.
  3. Guard getRefType() callers and skip filter creation when the type is null.
Defensive patterns

Strategy: validation

Validate before calling

const type = getRefType(vars, ref);
if (!type) { /* skip filter or re-resolve variable metadata */ }

Type guard

const refTypeResolvable = (vars: Variable[], ref: VariableRef): boolean => Boolean(getRefType(vars, ref));

Prevention

When it happens

Trigger: Building a default filter for a ref whose backing variable has an unknown/unsupported type, or referencing a variable id that no longer has metadata.

Common situations: A column/property type was changed or removed after a filter ref was created; corrupted variable metadata; referencing a computed variable with no resolvable type.

Related errors


AI-assisted analysis of toeverything/AFFiNE@26c515e050 (2026-08-12). Data as JSON: /api/errors/505c6f60b9795c5a. Report an issue: GitHub.