ruvnet/ruflo · error

EventStore not initialized. Call initialize() first.

Error message

EventStore not initialized. Call initialize() first.

What it means

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.

Source

Thrown at v3/@claude-flow/shared/src/events/event-store.ts:594

  private rowToEvent(row: any): DomainEvent {
    return {
      id: row.id as string,
      type: row.type as string,
      aggregateId: row.aggregate_id as string,
      aggregateType: row.aggregate_type as any,
      version: row.version as number,
      timestamp: row.timestamp as number,
      source: row.source as any,
      payload: JSON.parse(row.payload as string),
      metadata: row.metadata ? JSON.parse(row.metadata as string) : undefined,
      causationId: row.causation_id as string | undefined,
      correlationId: row.correlation_id as string | undefined,
    };
  }

  private ensureInitialized(): void {
    if (!this.initialized || !this.db) {
      throw new Error('EventStore not initialized. Call initialize() first.');
    }
  }
}

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Await initialize() before any other EventStore call and let its failure propagate
  2. If initialize() itself failed, fix the root cause (database path, permissions, disk) rather than catching and continuing
  3. After close(), construct a fresh EventStore instead of reusing the old instance

Example fix

// before
const store = new EventStore(config);
store.append(event); // throws: not initialized

// after
const store = new EventStore(config);
await store.initialize();
await store.append(event);
Defensive patterns

Strategy: validation

Validate before calling

await store.initialize(); // must complete (and may throw) before any other call
await store.append(event);

Try / catch

try {
  await store.getEvents(aggregateId);
} catch (e) {
  if (e instanceof Error && e.message.includes('not initialized')) {
    await store.initialize();
    await store.getEvents(aggregateId);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/e75beabedc473f48. Report an issue: GitHub.