ruvnet/ruflo · error · Error

Store not initialized. Call initialize() first.

Error message

Store not initialized. Call initialize() first.

What it means

PatternStore#search() throws this when this.registry is null. The registry is only populated by the async initialize() method, which dynamically imports discovery/download/publish modules and calls discovery.discoverRegistry(). Critically, initialize() returns false instead of throwing when registry discovery fails, so awaiting it is not enough — you must also check its boolean result before calling search().

Source

Thrown at v3/@claude-flow/cli/src/transfer/store/index.ts:131

    this.discovery = new PatternDiscovery(this.config);
    this.downloader = new PatternDownloader(this.config);
    this.publisher = new PatternPublisher(this.config);

    const result = await this.discovery.discoverRegistry(registryName);
    if (result.success && result.registry) {
      this.registry = result.registry;
      return true;
    }
    return false;
  }

  /**
   * Search patterns
   */
  search(options: SearchOptions = {}): SearchResult {
    if (!this.registry) {
      throw new Error('Store not initialized. Call initialize() first.');
    }
    return doSearchPatterns(this.registry, options);
  }

  /**
   * Get pattern by ID
   */
  getPattern(patternId: string): PatternEntry | undefined {
    if (!this.registry) {
      throw new Error('Store not initialized. Call initialize() first.');
    }
    return this.registry.patterns.find(p => p.id === patternId);
  }

  /**
   * Download pattern
   */
  async download(

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Call and await initialize() before any registry-backed method: `await store.initialize()`.
  2. Check the result: `if (!(await store.initialize())) { throw new Error('pattern registry unreachable'); }` so discovery failures surface immediately instead of later as this error.
  3. If initialize() returns false, debug the environment: network access and the registry config (StoreConfig) passed to the constructor.
  4. In long-lived processes, re-initialize after connectivity outages instead of reusing a failed store.

Example fix

// before
const store = new PatternStore(config);
const results = store.search({ query: 'auth' }); // throws: Store not initialized

// after
const store = new PatternStore(config);
const ready = await store.initialize();
if (!ready) throw new Error('registry discovery failed — check network/registry config');
const results = store.search({ query: 'auth' });
Defensive patterns

Strategy: validation

Validate before calling

const store = new PatternStore(config);
const ready = await store.initialize();
if (!ready) {
  throw new Error('PatternStore init failed: registry unreachable — check network/registry config');
}
// only now is search() safe
const results = store.search({ query: 'auth' });

Try / catch

try {
  return store.search(options);
} catch (err) {
  if (err instanceof Error && err.message === 'Store not initialized. Call initialize() first.') {
    if (!(await store.initialize())) throw new Error('registry discovery failed');
    return store.search(options); // retry once after proper init
  }
  throw err;
}

Prevention

When it happens

Trigger: (1) `const store = new PatternStore(); store.search({...})` without ever calling initialize(); (2) calling search() before `await store.initialize()` resolves (e.g. constructor-time or module-top-level usage); (3) initialize() was awaited but returned false because discoverRegistry() failed (offline, bad registry URL) and the caller ignored the return value.

Common situations: Refactoring that moved initialization into a constructor or top-level code; unit tests that construct PatternStore directly without mocks for discovery; running in a sandbox with no network access to the pattern registry, so initialize() quietly returns false.

Related errors


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