{"record":{"id":"e75beabedc473f48","repo":"ruvnet/ruflo","slug":"eventstore-not-initialized-call-initialize-firs","errorCode":null,"errorMessage":"EventStore not initialized. Call initialize() first.","messagePattern":"EventStore not initialized\\. Call initialize\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/shared/src/events/event-store.ts","lineNumber":594,"sourceCode":"  private rowToEvent(row: any): DomainEvent {\n    return {\n      id: row.id as string,\n      type: row.type as string,\n      aggregateId: row.aggregate_id as string,\n      aggregateType: row.aggregate_type as any,\n      version: row.version as number,\n      timestamp: row.timestamp as number,\n      source: row.source as any,\n      payload: JSON.parse(row.payload as string),\n      metadata: row.metadata ? JSON.parse(row.metadata as string) : undefined,\n      causationId: row.causation_id as string | undefined,\n      correlationId: row.correlation_id as string | undefined,\n    };\n  }\n\n  private ensureInitialized(): void {\n    if (!this.initialized || !this.db) {\n      throw new Error('EventStore not initialized. Call initialize() first.');\n    }\n  }\n}\n","sourceCodeStart":576,"sourceCodeEnd":598,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/shared/src/events/event-store.ts#L576-L598","documentation":"Every EventStore operation funnels through the private ensureInitialized() guard, which throws unless initialize() completed and the backing database handle exists. It fires when append/query/getSnapshot calls run before initialization, when initialize() itself failed (e.g. the database could not be opened) and the rejection was swallowed, or after the store was closed. The guard turns would-be silent no-ops into a loud usage error.","triggerScenarios":"Calling store.append() or store.getEvents() without awaiting store.initialize() first; a bootstrap path that calls initialize() without await and continues immediately; reusing a store instance after close(); initialize() failing on a bad path or permissions while the caller ignores the error.","commonSituations":"Missing await on initialize() in async bootstrapping; DI containers constructing the EventStore lazily while handlers fire before startup completes; tests that build the store but skip initialization.","solutions":["Await initialize() before any other EventStore call and let its failure propagate","If initialize() itself failed, fix the root cause (database path, permissions, disk) rather than catching and continuing","After close(), construct a fresh EventStore instead of reusing the old instance"],"exampleFix":"// before\nconst store = new EventStore(config);\nstore.append(event); // throws: not initialized\n\n// after\nconst store = new EventStore(config);\nawait store.initialize();\nawait store.append(event);","handlingStrategy":"validation","validationCode":"await store.initialize(); // must complete (and may throw) before any other call\nawait store.append(event);","typeGuard":null,"tryCatchPattern":"try {\n  await store.getEvents(aggregateId);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('not initialized')) {\n    await store.initialize();\n    await store.getEvents(aggregateId);\n  } else throw e;\n}","preventionTips":["Await initialize() in the startup path and let failures abort boot","Never call store operations from constructors or module top-level before init resolves","After close(), build a new EventStore instance"],"tags":["event-store","initialization","lifecycle","event-sourcing"],"backgroundTag":"not-initialized","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}