{"record":{"id":"505c6f60b9795c5a","repo":"toeverything/AFFiNE","slug":"databaseblockerror-505c6f","errorCode":"DatabaseBlockError","errorMessage":"can't resolve ref type","messagePattern":"can't resolve ref type","errorType":"exception","errorClass":"BlockSuiteError","httpStatus":null,"severity":"error","filePath":"blocksuite/affine/data-view/src/core/filter/utils.ts","lineNumber":11,"sourceCode":"import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';\n\nimport { getRefType } from '../expression/ref/ref.js';\nimport type { Variable, VariableRef } from '../expression/types.js';\nimport { filterMatcher } from './filter-fn/matcher.js';\nimport type { FilterGroup, SingleFilter } from './types.js';\n\nexport const firstFilterName = (vars: Variable[], ref: VariableRef) => {\n  const type = getRefType(vars, ref);\n  if (!type) {\n    throw new BlockSuiteError(\n      ErrorCode.DatabaseBlockError,\n      `can't resolve ref type`\n    );\n  }\n  return filterMatcher.firstMatchedBySelfType(type)?.name;\n};\nexport const firstFilterByRef = (\n  vars: Variable[],\n  ref: VariableRef\n): SingleFilter => {\n  return {\n    type: 'filter',\n    left: ref,\n    function: firstFilterName(vars, ref),\n    args: [],\n  };\n};\nexport const firstFilter = (vars: Variable[]): SingleFilter => {","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/affine/data-view/src/core/filter/utils.ts#L1-L29","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the referenced variable has a registered, resolvable type before constructing a filter.","Re-resolve or migrate filter refs after column type changes.","Guard getRefType() callers and skip filter creation when the type is null."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const type = getRefType(vars, ref);\nif (!type) { /* skip filter or re-resolve variable metadata */ }","typeGuard":"const refTypeResolvable = (vars: Variable[], ref: VariableRef): boolean => Boolean(getRefType(vars, ref));","tryCatchPattern":null,"preventionTips":["Re-resolve filter refs after column type changes","Ensure referenced variables carry resolvable type metadata"],"tags":["data-view","filter","type","database"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}