{"record":{"id":"41aef0d6c8471999","repo":"mastra-ai/mastra","slug":"factory-storage-domain-name-must-not-be-empty","errorCode":null,"errorMessage":"Factory storage domain name must not be empty","messagePattern":"Factory storage domain name must not be empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/factory-storage.ts","lineNumber":221,"sourceCode":"   */\n  updateAtomic<T extends Record<string, unknown>>(\n    collection: string,\n    where: CollectionWhere,\n    fn: (row: T) => Partial<T> | null | Promise<Partial<T> | null>,\n  ): Promise<T | null>;\n}\n\n/**\n * Base class for application domains owned by a {@link FactoryStorage}.\n * Domains are bound once when registered and share their owner's connection.\n */\nexport abstract class FactoryStorageDomain extends StorageDomain {\n  override readonly name: string;\n  #storage?: FactoryStorage;\n\n  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;","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/factory-storage.ts#L203-L239","documentation":"FactoryStorageDomain's protected constructor validates that the domain name is a non-empty, non-whitespace string. Every domain (workspaces, traces, etc.) is registered and looked up by name, so an empty name would create an unaddressable, colliding domain. This fires when subclass code passes '' or whitespace to super().","triggerScenarios":"Writing a custom domain with constructor() { super(''); } or super(name) where name is undefined/'' at call time; destructuring a config that omitted the name field; template-string names built from empty env vars.","commonSituations":"Extending FactoryStorageDomain for custom storage domains; renaming/refactoring that dropped a literal name argument; environment-driven domain naming where an env var is unset.","solutions":["Pass a literal non-empty name to super(), e.g. super('my-domain')","If the name comes from config/env, default it: super(process.env.DOMAIN_NAME ?? 'my-domain')","Add a startup assertion for the env value before constructing the domain","Check for accidental argument-order mistakes in the subclass constructor"],"exampleFix":"// before\nclass TracesDomain extends FactoryStorageDomain {\n  constructor(name?: string) {\n    super(name ?? ''); // throws when name is undefined\n  }\n}\n// after\nclass TracesDomain extends FactoryStorageDomain {\n  constructor(name = 'traces') {\n    super(name);\n  }\n}","handlingStrategy":"validation","validationCode":"const name = process.env.MY_DOMAIN_NAME;\nif (typeof name !== 'string' || !name.trim()) throw new Error('MY_DOMAIN_NAME must be a non-empty string');\nclass MyDomain extends FactoryStorageDomain { constructor() { super(name); } }","typeGuard":"function isNonEmptyName(name: unknown): name is string {\n  return typeof name === 'string' && name.trim().length > 0;\n}","tryCatchPattern":"try {\n  domain = new MyDomain();\n} catch (err) {\n  if (err instanceof Error && err.message === 'Factory storage domain name must not be empty') {\n    throw new Error('Domain construction failed: pass a non-empty name to super()');\n  }\n  throw err;\n}","preventionTips":["Always pass literal, non-empty names to super() in custom domains","Default optional name params at the constructor signature, not with ''","Validate env/config-sourced names before constructing domains","Keep name arguments positional-simple to avoid argument-order mistakes"],"tags":["storage","factory","validation","configuration"],"backgroundTag":"invalid-configuration","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}