{"record":{"id":"23065aba3eea250c","repo":"toeverything/AFFiNE","slug":"schemavalidateerror","errorCode":"SchemaValidateError","errorMessage":"Invalid schema for ${flavour}: Schema not found. The block flavour may not be registered.","messagePattern":"Invalid schema for (.+?): 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/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/framework/store/src/schema/schema.ts#L47-L83","documentation":"Thrown by Schema.validate() when the primary block flavour being validated is not present in the flavourSchemaMap. BlockSuite maintains a registry of block schemas (flavours) and this error indicates the flavour string was never registered via Schema.register() before being used. The error surfaces during any structural validation that checks parent/child relationships for a block tree.","triggerScenarios":"Calling schema.validate('affine:unknown', parentFlavour, childFlavours) where 'affine:unknown' was never registered. Also triggered indirectly by Store.addBlock() or any operation that constructs or mutates block trees when the flavour has not been registered on the Schema instance.","commonSituations":"Forgetting to call Schema.register([...]) with the full block schema array before creating a doc. Using a custom block flavour string that has a typo or mismatch with the registered flavour name. Dynamic plugin/extension loading where the block definition module was not imported before block creation. Version upgrades where a flavour was renamed or removed.","solutions":["Check that the flavour string exactly matches the flavour defined in the block's schema definition (including the namespace prefix like 'affine:').","Ensure Schema.register([BlockSchema1, BlockSchema2, ...]) is called with all block schemas before any doc/store operations that reference them.","Verify the block definition module (e.g. the file calling defineBlockSchema) is imported as a side-effect so the schema is available at runtime.","Use schema.get(flavour) to check existence before calling validate, or use schema.safeValidate() which returns false instead of throwing."],"exampleFix":"// before\nconst schema = new Schema();\n// forgot to register\ndoc.addBlock('affine:paragraph', {}); // throws SchemaValidateError\n\n// after\nimport { ParagraphBlockSchema } from './blocks/paragraph';\nconst schema = new Schema();\nschema.register([ParagraphBlockSchema /* , ...other schemas */]);\ndoc.addBlock('affine:paragraph', {});","handlingStrategy":"validation","validationCode":"if (!schema.get(flavour)) {\n  throw new Error(`Flavour '${flavour}' is not registered. Register it via Schema.register([...]) first.`);\n}\nschema.validate(flavour, parentFlavour, childFlavours);","typeGuard":"const isRegisteredFlavour = (schema: Schema, flavour: string): boolean =>\n  schema.flavourSchemaMap.has(flavour);","tryCatchPattern":"try {\n  schema.validate(flavour, parentFlavour, childFlavours);\n} catch (e) {\n  if (e instanceof SchemaValidateError) {\n    console.error(`Schema validation failed for ${flavour}: ${e.message}`);\n    // handle: register missing schema or skip the block\n  }\n  throw e;\n}","preventionTips":["Register all block schemas in a single central place before any Store/Doc is created.","Use a Schema initialization function that's called once at app startup.","Prefer schema.safeValidate() (returns boolean) when you want non-throwing checks."],"tags":["blocksuite","schema","block-registration","validation"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}