{"record":{"id":"6c8b7312c3c8e08d","repo":"toeverything/AFFiNE","slug":"errorcode-modelcruderror-6c8b73","errorCode":"ErrorCode.ModelCRUDError","errorMessage":"schema for flavour: ${flavour} not found","messagePattern":"schema for flavour: (.+?) not found","errorType":"exception","errorClass":"BlockSuiteError","httpStatus":null,"severity":"error","filePath":"blocksuite/framework/store/src/model/store/crud.ts","lineNumber":55,"sourceCode":"    if (!parent) return null;\n\n    const children = parent.get('sys:children');\n    const index = children.toArray().indexOf(id);\n    if (index === -1) return null;\n\n    return fn(index, parent);\n  }\n\n  addBlock(\n    id: string,\n    flavour: string,\n    initialProps: Record<string, unknown> = {},\n    parent?: string | null,\n    parentIndex?: number\n  ) {\n    const schema = this._schema.flavourSchemaMap.get(flavour);\n    if (!schema) {\n      throw new BlockSuiteError(\n        ErrorCode.ModelCRUDError,\n        `schema for flavour: ${flavour} not found`\n      );\n    }\n\n    const hasBlock = this._yBlocks.has(id);\n    if (hasBlock) {\n      throw new BlockSuiteError(\n        ErrorCode.ModelCRUDError,\n        `Should not add existing block: ${id}`\n      );\n    }\n\n    const parentFlavour = parent\n      ? this._yBlocks.get(parent)?.get('sys:flavour')\n      : undefined;\n\n    this._schema.validate(flavour, parentFlavour as string);","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/framework/store/src/model/store/crud.ts#L37-L73","documentation":"Thrown by DocCRUD.addBlock: the flavour passed in is not present in schema.flavourSchemaMap. This is the public write-path equivalent of the parse-path schema errors; addBlock needs the schema to compute the version, default props, and validate parent/child rules, so an unknown flavour is rejected before any Yjs mutation.","triggerScenarios":"Calling store.addBlock('affine:foo', ...) where 'affine:foo' was never registered; passing a typo'd or stale flavour string; using a flavour from a different BlockSuite major version.","commonSituations":"Hard-coded flavour strings that drift from the registered schema; feature-flagged block not registered in the current build; copy-paste of a flavour literal that has since been renamed; SSR build omitting client-only block modules.","solutions":["Register the flavour's schema before calling addBlock.","Pull flavour constants from the block package's exports instead of hard-coding strings.","Add a schema.has(flavour) precondition check (or unit test) at call sites that accept dynamic flavours.","If the flavour was renamed, migrate callers or add an alias in the schema."],"exampleFix":"// before\nstore.addBlock('affine:list', { type: 'bulleted' }, parent);\n\n// after: import the flavour constant\nimport { ListBlockSchema } from '@blocksuite/affine/blocks/list';\nschema.register([ListBlockSchema]);\nstore.addBlock(ListBlockSchema.model.flavour, { type: 'bulleted' }, parent);","handlingStrategy":"type-guard","validationCode":"export function assertCanAddBlock(store: Store, flavour: string): void {\n  if (!store.schema.flavourSchemaMap.has(flavour)) {\n    throw new Error(`Cannot addBlock: flavour '${flavour}' not registered`);\n  }\n}\n\nassertCanAddBlock(store, 'affine:paragraph');\nstore.addBlock('affine:paragraph', {}, parent);","typeGuard":"export const isAddableFlavour = (store: Store, flavour: string): boolean =>\n  store.schema.flavourSchemaMap.has(flavour);","tryCatchPattern":"try {\n  store.addBlock(flavour, props, parent);\n} catch (e) {\n  if (e instanceof BlockSuiteError && e.code === ErrorCode.ModelCRUDError && /schema for flavour/.test(e.message)) {\n    disableUiForFlavour(flavour); // or register then retry\n  } else throw e;\n}","preventionTips":["Source flavour strings from schema constants rather than literals.","Register every flavour at app startup, before any user action.","Unit-test addBlock call paths against the registered schema.","Guard dynamic-flavour call sites with schema.flavourSchemaMap.has."],"tags":["model-crud","schema","addblock","flavour-registration"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}