{"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/b4c8548c09da21b2898443559a5b846f0ccf5dd8/blocksuite/framework/std/src/view/decorators/required.ts#L13-L49","documentation":"The @requiredProperties decorator (blocksuite/framework/std/src/view/decorators/required.ts) validates declared props each time the decorated LitElement's connectedCallback runs. If a listed property is still undefined at connect time, it throws this DefaultRuntimeError naming the property and the component class. It exists to fail fast when a block/view component is instantiated without the data it needs to render.","triggerScenarios":"Mounting a component decorated with @requiredProperties({ model: PropTypes.object, ... }) without setting every listed property first — e.g. creating the element imperatively via document.createElement and appending it before assigning props, or rendering it in a template without binding an attribute.","commonSituations":"Using BlockSuite view components outside the standard view registry (storybooks, previews, tests); forgetting a newly added required prop in a subclass; Lit property timing issues where attributes are set after connect.","solutions":["Pass every required property before the element connects (set properties on the instance before appending, or bind them in the Lit template).","If the prop is genuinely optional, remove it from the decorator's propTypes map or give the class a default value.","In tests/storybooks, construct via the standard view path or set props prior to appending to the DOM.","Check the error message for the exact property name and class, then set that prop."],"exampleFix":"// before\nconst el = new MyBlockComponent();\ndocument.body.append(el); // connectedCallback fires, props still undefined\nel.store = store;\n\n// after\nconst el = new MyBlockComponent();\nel.store = store;\nel.model = model;\ndocument.body.append(el);","handlingStrategy":"validation","validationCode":"// Before appending a decorated component, assert required props:\nconst el = new MyBlockComponent();\nel.store = store;\nel.model = model;\nconst missing = ['store', 'model'].filter(k => (el as any)[k] === undefined);\nif (missing.length === 0) document.body.append(el);","typeGuard":"function hasRequiredProps(el: LitElement, props: string[]): boolean {\n  return props.every(p => (el as any)[p] !== undefined);\n}","tryCatchPattern":null,"preventionTips":["Set all required properties before appending/connecting decorated elements.","Keep tests/storybooks in sync with the @requiredProperties map when adding props.","Give class-level defaults to props that may legitimately start undefined."],"tags":["blocksuite","lit","decorator","validation","component-lifecycle"],"backgroundTag":"missing-required-argument","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"}