{"record":{"id":"f52d383e8367c42b","repo":"toeverything/AFFiNE","slug":"errorcode-defaultruntimeerror","errorCode":"ErrorCode.DefaultRuntimeError","errorMessage":"Property ${propName} is required to ${instance.constructor.name}.","messagePattern":"Property (.+?) is required to (.+?)\\.","errorType":"exception","errorClass":"BlockSuiteError","httpStatus":null,"severity":"error","filePath":"blocksuite/framework/std/src/view/decorators/required.ts","lineNumber":31,"sourceCode":"  instanceOf: (expectedClass: Constructor) => (value: unknown) =>\n    value instanceof expectedClass,\n  arrayOf: (validator: ValidatorFunction) => (value: unknown) =>\n    Array.isArray(value) && value.every(validator),\n  recordOf: (validator: ValidatorFunction) => (value: unknown) => {\n    if (typeof value !== 'object' || value === null) return false;\n    return Object.values(value).every(validator);\n  },\n  of: (validator: ValidatorFunction) => (value: unknown) => validator(value),\n};\n\nfunction validatePropTypes<T extends InstanceType<Constructor>>(\n  instance: T,\n  propTypes: Record<string, ValidatorFunction>\n) {\n  for (const [propName, validator] of Object.entries(propTypes)) {\n    const key = propName as keyof T;\n    if (instance[key] === undefined) {\n      throw new BlockSuiteError(\n        ErrorCode.DefaultRuntimeError,\n        `Property ${propName} is required to ${instance.constructor.name}.`\n      );\n    }\n    if (validator && !validator(instance[key])) {\n      throw new BlockSuiteError(\n        ErrorCode.DefaultRuntimeError,\n        `Property ${propName} is invalid to ${instance.constructor.name}.`\n      );\n    }\n  }\n}\n\nexport function requiredProperties(\n  propTypes: Record<string, ValidatorFunction>\n) {\n  return function (constructor: Constructor<LitElement>) {\n    const connectedCallback = constructor.prototype.connectedCallback;","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/framework/std/src/view/decorators/required.ts#L13-L49","documentation":"Thrown by `validatePropTypes` inside the `@requiredProperties` decorator (required.ts). When a LitElement decorated with `@requiredProperties({...})` calls `connectedCallback`, each declared property is checked; if any is `undefined`, this error fires naming the missing property and component class. It is a compile-time-like runtime contract: the consumer forgot to bind a required property.","triggerScenarios":"A `@requiredProperties`-decorated block/component is mounted (connected) without one of the declared properties being set — e.g. `<my-block>` rendered without `.model` or `.store`.","commonSituations":"Forgetting to pass a required property/attribute when composing a block; conditional rendering that yields a block before its props are ready; refactoring a component and adding a new required prop without updating call sites.","solutions":["Pass the named property before the element connects: `<my-block .model=${model} .store=${store}></my-block>`.","If the property is genuinely optional, remove it from the `@requiredProperties` map or change it to a validator that permits `undefined`.","Ensure parent templates do not render the component until all required data is non-undefined."],"exampleFix":"// before: required prop not bound\n@requiredProperties({ model: PropTypes.object })\nclass MyBlock extends LitElement {}\nhtml`<my-block></my-block>`\n\n// after: bind the prop before connect\nhtml`<my-block .model=${model}></my-block>`","handlingStrategy":"validation","validationCode":"// before rendering a @requiredProperties-decorated component, ensure props are set\nfunction hasRequiredProps(\n  props: Record<string, unknown>,\n  required: string[]\n): boolean {\n  return required.every(k => props[k] !== undefined);\n}\n\nconst required = ['model', 'store'];\nif (hasRequiredProps({ model, store }, required)) {\n  render(html`<my-block .model=${model} .store=${store}></my-block>`, container);\n}","typeGuard":"function hasAllRequired<T extends object>(obj: T, keys: Array<keyof T>): obj is T {\n  return keys.every(k => obj[k] !== undefined);\n}","tryCatchPattern":"import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';\n\ntry {\n  container.appendChild(myBlock); // triggers connectedCallback -> validatePropTypes\n} catch (e) {\n  if (e instanceof BlockSuiteError && e.code === ErrorCode.DefaultRuntimeError) {\n    console.error('Missing required property:', e.message);\n  }\n}","preventionTips":["Bind all properties declared in @requiredProperties before the element connects.","Treat the decorator map as the source of truth for required bindings.","Add unit tests that mount the component with each prop omitted to catch regressions."],"tags":["decorator","lit","validation","block-component"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}