{"record":{"id":"4774c2f41bc0fe49","repo":"linshenkx/prompt-optimizer","slug":"read-4774c2","errorCode":"read","errorMessage":"Failed to get item: ${key}","messagePattern":"Failed to get item: (.+?)","errorType":"exception","errorClass":"StorageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/storage/dexieStorageProvider.ts","lineNumber":101,"sourceCode":"   * 重置迁移状态（主要用于测试）\n   */\n  static resetMigrationState(): void {\n    // 因为迁移逻辑已移除，此函数不再需要\n    // 保留为空函数以避免破坏测试的API\n  }\n\n  /**\n   * 获取存储项\n   */\n  async getItem(key: string): Promise<string | null> {\n    await this.initialize();\n    \n    try {\n      const record = await this.db.storage.get(key);\n      return record?.value ?? null;\n    } catch (error) {\n      console.error(`Failed to get storage item (${key}):`, error);\n      throw new StorageError(`Failed to get item: ${key}`, 'read');\n    }\n  }\n\n  /**\n   * 设置存储项\n   */\n  async setItem(key: string, value: string): Promise<void> {\n    await this.initialize();\n    \n    try {\n      await this.db.storage.put({\n        key,\n        value,\n        timestamp: Date.now()\n      });\n    } catch (error) {\n      console.error(`Failed to set storage item (${key}):`, error);\n      throw new StorageError(`Failed to set item: ${key}`, 'write');","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/storage/dexieStorageProvider.ts#L83-L119","documentation":"StorageError with code 'read' thrown by DexieStorageProvider.getItem when the underlying Dexie table lookup (this.db.storage.get(key)) rejects. Dexie rejections typically stem from database being closed, schema mismatch, IndexedDB being blocked/unavailable, or quota/private-mode restrictions in the browser.","triggerScenarios":"Calling getItem(key) after the Dexie database was closed, when the 'storage' table doesn't exist due to a schema/version mismatch, or when IndexedDB access fails (private browsing, storage corrupted, deleted while open).","commonSituations":"App updated with a changed schema but old DB version present; running in a private/incognito window with restricted IndexedDB; another tab forced a version upgrade blocking this connection; user cleared storage while the app held it open.","solutions":["Check console output — the original Dexie error is logged before wrapping","Ensure the Dexie database is open and the schema version includes the 'storage' table; bump the version and provide an upgrade handler if the schema changed","Retry after reopening the database (db.open()) or reloading the app; verify IndexedDB is available in the environment"],"exampleFix":"// before\nconst v = await provider.getItem('k');\n\n// after\nif (!provider.db.isOpen()) await provider.db.open();\nconst v = await provider.getItem('k').catch(e => { console.warn('read failed', e); return null; });","handlingStrategy":"try-catch","validationCode":"if (!provider.db.isOpen()) await provider.db.open(); // or provider.initialize()","typeGuard":"const isStorageReadError = (e: unknown): e is StorageError =>\n  e instanceof StorageError && (e as StorageError).code === 'read';","tryCatchPattern":"try { return await provider.getItem(key); } catch (e) { if (isStorageReadError(e)) return null; /* missing/corrupt read treated as absent */ throw e; }","preventionTips":["Call initialize() once at app start and reuse the instance","Bump Dexie schema versions with upgrade paths to avoid table-mismatch errors","Log the original console.error output — it carries the true Dexie cause"],"tags":["storage","indexeddb","dexie"],"backgroundTag":"indexeddb-operation-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}