{"record":{"id":"b649fa32e5b9077c","repo":"mastra-ai/mastra","slug":"factory-storage-domain-this-name-has-not-been","errorCode":null,"errorMessage":"Factory storage domain '${this.name}' has not been registered","messagePattern":"Factory storage domain '(.+?)' has not been registered","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/factory-storage.ts","lineNumber":237,"sourceCode":"  protected constructor(name: string) {\n    if (!name.trim()) {\n      throw new Error('Factory storage domain name must not be empty');\n    }\n    super({ component: 'STORAGE', name });\n    this.name = name;\n  }\n\n  /** @internal Bound by {@link FactoryStorage.registerDomain}. */\n  __bindFactoryStorage(storage: FactoryStorage): void {\n    if (this.#storage && this.#storage !== storage) {\n      throw new Error(`Factory storage domain '${this.name}' is already bound to another storage instance`);\n    }\n    this.#storage = storage;\n  }\n\n  protected get storage(): FactoryStorage {\n    if (!this.#storage) {\n      throw new Error(`Factory storage domain '${this.name}' has not been registered`);\n    }\n    return this.#storage;\n  }\n\n  /**\n   * Initialize this domain (via its owning storage) if it hasn't been yet.\n   * Lets consumers holding a domain handle run the same fail-soft readiness\n   * check as {@link FactoryStorage.ensureDomainReady} without also needing a\n   * reference to the storage backend.\n   */\n  ensureReady(): Promise<void> {\n    return this.storage.ensureDomainReady(this.name);\n  }\n\n  protected get ops(): FactoryStorageOps {\n    return this.storage.ops;\n  }\n","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/factory-storage.ts#L219-L255","documentation":"A FactoryStorageDomain's underlying storage backend is only wired up when the owning storage class registers the domain (via registerDomain/__bindFactoryStorage). The protected `storage` getter throws when a domain is used before that binding happened, i.e. the domain object exists but no storage was ever attached to it.","triggerScenarios":"Instantiating a domain class (or subclass) and calling any method that reads `this.storage` without first registering it with a storage instance via `registerDomain()` / running the owning storage's `init()`.","commonSituations":"Constructing a domain directly with `new` in tests or custom code instead of getting it from the storage class; custom storage backends whose initStorage() forgets to register a domain; accessing a domain at module load time before storage init.","solutions":["Register the domain with its owning storage instance before using it: `storage.registerDomain(domain)`.","Ensure the storage class's `initStorage()` implementation registers all domains (intakeStorage, memorySettingsStorage, etc.).","Call the storage's `init()`/initialization method before touching any domain methods.","In tests, use the storage factory/helper that wires domains instead of constructing domain objects directly."],"exampleFix":"// before\nconst domains = new InMemoryMemorySettingsStorage();\ndomains.getSettings(); // throws: domain not registered\n\n// after\nconst storage = new MastraStorage({ name: 'my-app' });\nconst domains = storage.registerDomain(new InMemoryMemorySettingsStorage());\nawait storage.init();\ndomains.getSettings(); // works","handlingStrategy":"validation","validationCode":"function isDomainReady(domain) {\n  return typeof domain.hasBeenInitialized === 'function'\n    ? domain.hasBeenInitialized()\n    : true;\n}\n// call after storage.init() and before using the domain","typeGuard":"function isBoundDomain(d) {\n  return d != null && typeof d === 'object' && 'storage' in d && (d.__factoryStorage ?? null) !== undefined;\n}","tryCatchPattern":"try {\n  await domain.doWork();\n} catch (e) {\n  if (e.message.includes(\"has not been registered\")) {\n    await storage.init();\n    return domain.doWork();\n  }\n  throw e;\n}","preventionTips":["Always obtain domains from the storage instance (storage.registerDomain / typed accessors), never construct them standalone.","Call storage.init() once during app bootstrap before any storage access.","In tests, build domains through the same factory path production code uses.","Add an integration test that exercises each domain after a fresh storage init."],"tags":["storage","initialization","lifecycle"],"backgroundTag":"dependency-not-initialized","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}