{"record":{"id":"2f2cddc48e0d08eb","repo":"toeverything/AFFiNE","slug":"errorcode-modelcruderror","errorCode":"ErrorCode.ModelCRUDError","errorMessage":"schema for flavour: ${this.flavour} not found","messagePattern":"schema for flavour: (.+?) not found","errorType":"exception","errorClass":"BlockSuiteError","httpStatus":null,"severity":"critical","filePath":"blocksuite/framework/store/src/model/block/flat-sync-controller.ts","lineNumber":43,"sourceCode":"    readonly schema: Schema,\n    readonly yBlock: YBlock,\n    readonly doc?: Store,\n    readonly onChange?: (key: string, isLocal: boolean) => void\n  ) {\n    const { id, flavour, version, yChildren, props } = this._parseYBlock();\n\n    this.id = id;\n    this.flavour = flavour;\n    this.yChildren = yChildren;\n    this.version = version;\n\n    this.model = this._createModel(props);\n  }\n\n  private _createModel(props: Set<string>) {\n    const schema = this.schema.flavourSchemaMap.get(this.flavour);\n    if (!schema) {\n      throw new BlockSuiteError(\n        ErrorCode.ModelCRUDError,\n        `schema for flavour: ${this.flavour} not found`\n      );\n    }\n\n    const model = schema.model.toModel?.() ?? new BlockModel<object>();\n    const defaultProps = schema.model.props?.(internalPrimitives);\n    model.schema = schema;\n\n    model.id = this.id;\n    model.keys = Array.from(props);\n    model.yBlock = this.yBlock;\n    const reactive = new ReactiveFlatYMap(\n      this.yBlock,\n      model.deleted,\n      this.onChange,\n      defaultProps\n    );","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/blocksuite/framework/store/src/model/block/flat-sync-controller.ts#L25-L61","documentation":"When a flat-data-model block is instantiated from its Yjs map, FlatSyncController resolves the block's sys:flavour in Schema.flavourSchemaMap before building the model. If no schema is registered under that flavour, the store cannot create the model and throws this ModelCRUDError during block hydration.","triggerScenarios":"Instantiating a Block for a Yjs block map whose sys:flavour is not registered on the Schema instance passed to the Store — e.g. a doc written by another build containing 'my:custom' flavours, or a flavour string that was renamed.","commonSituations":"Forgetting schema.register([...]) before loading persisted docs; opening documents produced by a different editor configuration; renaming or splitting a block flavour without migrating old docs; schemas lazy-loaded after the doc has already mounted.","solutions":["Register every flavour the doc can contain via schema.register([...schemas]) before the doc is loaded","Inspect the doc's blocks Y.Map and collect all sys:flavour values to find which one is missing from doc.schema.flavourSchemaMap","If a flavour was renamed, add a migration that rewrites sys:flavour on old blocks or register a legacy schema","As a last resort for disposable data, delete the offending block from the snapshot and let the doc load"],"exampleFix":"// before\nconst schema = new Schema();\nconst doc = workspace.createSession({ id: 'doc1', schema });\n// doc1 contains 'my:flat' blocks -> schema for flavour: my:flat not found\n\n// after\nconst schema = new Schema();\nschema.register([MyFlatBlock]); // defineBlockSchema({ flavour: 'my:flat', isFlatData: true, ... })\nconst doc = workspace.createSession({ id: 'doc1', schema });","handlingStrategy":"validation","validationCode":"for (const [, yBlock] of doc.getBlockMap()) {\n  const flavour = yBlock.get('sys:flavour') as string;\n  if (!doc.schema.flavourSchemaMap.has(flavour)) {\n    console.warn('unregistered flavour in doc:', flavour);\n  }\n}","typeGuard":"const isFlavourRegistered = (schema: Schema, flavour: string): boolean =>\n  schema.flavourSchemaMap.has(flavour);","tryCatchPattern":"try {\n  const doc = workspace.createSession({ id, schema });\n} catch (e) {\n  if (e instanceof BlockSuiteError && e.code === ErrorCode.ModelCRUDError) {\n    // log flavour registry and doc contents, register missing schemas, retry load\n  }\n  throw e;\n}","preventionTips":["Register all block schemas in one place before any doc loads","Log schema.flavourSchemaMap keys whenever hydration fails to spot the missing flavour fast","Keep legacy flavour schemas registered when renaming blocks"],"tags":["blocksuite","schema","flavour","registration","flat-data-model"],"backgroundTag":"missing-schema-registration","analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}