{"record":{"id":"614d65e7af15ea33","repo":"ruvnet/ruflo","slug":"store-not-initialized-call-initialize-first","errorCode":null,"errorMessage":"Store not initialized. Call initialize() first.","messagePattern":"Store not initialized\\. Call initialize\\(\\) first\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/transfer/store/index.ts","lineNumber":131,"sourceCode":"\n    this.discovery = new PatternDiscovery(this.config);\n    this.downloader = new PatternDownloader(this.config);\n    this.publisher = new PatternPublisher(this.config);\n\n    const result = await this.discovery.discoverRegistry(registryName);\n    if (result.success && result.registry) {\n      this.registry = result.registry;\n      return true;\n    }\n    return false;\n  }\n\n  /**\n   * Search patterns\n   */\n  search(options: SearchOptions = {}): SearchResult {\n    if (!this.registry) {\n      throw new Error('Store not initialized. Call initialize() first.');\n    }\n    return doSearchPatterns(this.registry, options);\n  }\n\n  /**\n   * Get pattern by ID\n   */\n  getPattern(patternId: string): PatternEntry | undefined {\n    if (!this.registry) {\n      throw new Error('Store not initialized. Call initialize() first.');\n    }\n    return this.registry.patterns.find(p => p.id === patternId);\n  }\n\n  /**\n   * Download pattern\n   */\n  async download(","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/transfer/store/index.ts#L113-L149","documentation":"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().","triggerScenarios":"(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.","commonSituations":"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.","solutions":["Call and await initialize() before any registry-backed method: `await store.initialize()`.","Check the result: `if (!(await store.initialize())) { throw new Error('pattern registry unreachable'); }` so discovery failures surface immediately instead of later as this error.","If initialize() returns false, debug the environment: network access and the registry config (StoreConfig) passed to the constructor.","In long-lived processes, re-initialize after connectivity outages instead of reusing a failed store."],"exampleFix":"// before\nconst store = new PatternStore(config);\nconst results = store.search({ query: 'auth' }); // throws: Store not initialized\n\n// after\nconst store = new PatternStore(config);\nconst ready = await store.initialize();\nif (!ready) throw new Error('registry discovery failed — check network/registry config');\nconst results = store.search({ query: 'auth' });","handlingStrategy":"validation","validationCode":"const store = new PatternStore(config);\nconst ready = await store.initialize();\nif (!ready) {\n  throw new Error('PatternStore init failed: registry unreachable — check network/registry config');\n}\n// only now is search() safe\nconst results = store.search({ query: 'auth' });","typeGuard":null,"tryCatchPattern":"try {\n  return store.search(options);\n} catch (err) {\n  if (err instanceof Error && err.message === 'Store not initialized. Call initialize() first.') {\n    if (!(await store.initialize())) throw new Error('registry discovery failed');\n    return store.search(options); // retry once after proper init\n  }\n  throw err;\n}","preventionTips":["Always await initialize() and branch on its boolean result — false means discovery failed even though nothing threw","Wrap store creation in a factory that returns an already-initialized store so callers cannot skip the step","In tests, mock discoverRegistry to succeed instead of constructing half-initialized stores","Log the initialize() return value; silent false is the root cause of most late 'not initialized' crashes"],"tags":["pattern-store","lifecycle","initialization","async","claude-flow"],"backgroundTag":"service-not-initialized","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}