{"record":{"id":"2161935d00090e04","repo":"toeverything/AFFiNE","slug":"schema-not-found-the-block-flavour-may-not-be-reg","errorCode":null,"errorMessage":"Schema not found. The block flavour may not be registered.","messagePattern":"Schema not found\\. The block flavour may not be registered\\.","errorType":"validation","errorClass":"SchemaValidateError","httpStatus":null,"severity":"error","filePath":"blocksuite/framework/store/src/schema/schema.ts","lineNumber":65,"sourceCode":"  }\n\n  /**\n   * Validates the schema relationship for a given flavour, parent, and children.\n   * Throws SchemaValidateError if invalid.\n   *\n   * @param flavour - The block flavour to validate.\n   * @param parentFlavour - The parent block flavour (optional).\n   * @param childFlavours - The child block flavours (optional).\n   * @throws {SchemaValidateError} If the schema relationship is invalid.\n   */\n  validate = (\n    flavour: string,\n    parentFlavour?: string,\n    childFlavours?: string[]\n  ): void => {\n    const schema = this.flavourSchemaMap.get(flavour);\n    if (!schema) {\n      throw new SchemaValidateError(flavour, SCHEMA_NOT_FOUND_MESSAGE);\n    }\n\n    const validateChildren = () => {\n      childFlavours?.forEach(childFlavour => {\n        const childSchema = this.flavourSchemaMap.get(childFlavour);\n        if (!childSchema) {\n          throw new SchemaValidateError(childFlavour, SCHEMA_NOT_FOUND_MESSAGE);\n        }\n        this.validateSchema(childSchema, schema);\n      });\n    };\n\n    if (schema.model.role === 'root') {\n      if (parentFlavour) {\n        throw new SchemaValidateError(\n          schema.model.flavour,\n          'Root block cannot have parent.'\n        );","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/blocksuite/framework/store/src/schema/schema.ts#L47-L83","documentation":"Schema.validate(flavour, parentFlavour?, childFlavours?) throws SchemaValidateError when the flavour is absent from flavourSchemaMap, meaning no schema was ever registered for that block. Registration happens via schema.register([...]) when the Store/Collection is created from a schema array. The error means the block package providing this flavour was not imported or included in that array.","triggerScenarios":"doc.addBlock('affine:xyz', ...) where 'affine:xyz' was never registered; schema.validate() on a flavour string with a typo; validating a snapshot that references a block from an uninstalled package.","commonSituations":"Custom block defined but not added to the schema array passed to the Store; missing side-effect import of a block bundle (@blocksuite/affine blocks); flavour renamed between versions so old strings no longer resolve.","solutions":["Add the missing block schema to the schema array used to create the Store/Collection (or call doc.schema.register([MissingBlock])).","Import the module that registers the block before creating the store.","Verify registration first: doc.schema.flavourSchemaMap.has(flavour) or doc.schema.get(flavour).","Check the flavour string for typos against schema.versions, which lists every registered flavour."],"exampleFix":"// before\nconst store = new Store({ id: 'doc' }); // custom block never registered\nawait doc.addBlock('my:custom-block', {}, parentId);\n\n// after\nimport { MyCustomBlock } from './my-custom-block.js';\nconst store = new Store({ id: 'doc', schema: [MyCustomBlock] });\nawait doc.addBlock('my:custom-block', {}, parentId);","handlingStrategy":"validation","validationCode":"if (!doc.schema.flavourSchemaMap.has(flavour)) {\n  throw new Error(`flavour ${flavour} is not registered; add it to the store schema`);\n}\nawait doc.addBlock(flavour, props, parentId);","typeGuard":"const isRegisteredFlavour = (schema: Schema, flavour: string): boolean =>\n  schema.flavourSchemaMap.has(flavour);","tryCatchPattern":"if (!doc.schema.safeValidate(flavour, parentFlavour)) {\n  // report unknown/invalid flavour without throwing\n} else {\n  doc.schema.validate(flavour, parentFlavour);\n}","preventionTips":["Import every block bundle and pass the full schema array when creating the Store/Collection.","In dev builds, assert doc.schema.versions contains all flavours your code references.","Prefer the non-throwing schema.get / safeValidate APIs for untrusted flavour strings."],"tags":["schema","block-registration","flavour","blocksuite"],"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-14T05:17:10.506Z"}