{"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":"error","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/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/framework/store/src/model/block/flat-sync-controller.ts#L25-L61","documentation":"Thrown by `FlatSyncController._createModel` when `schema.flavourSchemaMap.get(this.flavour)` returns undefined. The controller is constructing a `BlockModel` from a yjs block map; the block's flavour has no matching schema, meaning the flavour was never registered with the `Schema` passed to the store. Note `_parseYBlock` already throws the same message earlier if the schema is missing there too.","triggerScenarios":"A yjs document contains a block whose `sys:flavour` is not in the schema — e.g. collaborative peer with a block flavour the local app does not register, a snapshot import of an unknown flavour, or the `Schema` was built without all the block `defineBlockSchema` calls.","commonSituations":"App build A registers `{affine:page}` and build B adds `{affine:custom}`; B's doc syncs to A and A throws. Forgetting to call `Schema` with all block flavours; lazy-loading a block flavour but the doc loads before the flavour registration completes.","solutions":["Register every flavour the doc may contain with the `Schema` before constructing the store / loading the doc.","Gate doc load on flavour registration being complete (await the module that registers the schema).","If you intentionally receive foreign flavours, filter them out of the yjs map before model creation, or register a stub schema."],"exampleFix":"// before: store built with a partial schema\nconst schema = new Schema([PageBlockSchema]);\nconst store = createStore({ schema, id: 'doc' });\nstore.load(binaryContainingCustomBlock); // throws: schema for flavour not found\n\n// after: register every flavour the doc may contain\nconst schema = new Schema([PageBlockSchema, CustomBlockSchema]);\nconst store = createStore({ schema, id: 'doc' });\nstore.load(binaryContainingCustomBlock);","handlingStrategy":"validation","validationCode":"// verify every flavour referenced by the doc is in the schema before loading\nfunction allFlavoursRegistered(schema: Schema, flavours: string[]): boolean {\n  return flavours.every(f => schema.flavourSchemaMap.has(f));\n}\n\nconst flavours = collectFlavoursFromYDoc(yDoc);\nif (!allFlavoursRegistered(schema, flavours)) {\n  throw new Error('Register all block flavours before loading the doc');\n}","typeGuard":"function schemaHasFlavour(schema: Schema, flavour: string): boolean {\n  return schema.flavourSchemaMap.has(flavour);\n}","tryCatchPattern":"try {\n  store.load(binary);\n} catch (e) {\n  if (e instanceof BlockSuiteError && e.code === ErrorCode.ModelCRUDError) {\n    console.error('Schema missing flavour:', e.message);\n  }\n}","preventionTips":["Register every block flavour with the Schema before constructing the store.","Gate doc load on flavour registration completing.","Filter or stub foreign flavours if you intentionally receive them."],"tags":["schema","block-model","flavour","registration","yjs"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}