{"record":{"id":"5a17a4cb43687940","repo":"linshenkx/prompt-optimizer","slug":"failed-to-clear-storage","errorCode":null,"errorMessage":"Failed to clear storage","messagePattern":"Failed to clear storage","errorType":"exception","errorClass":"StorageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/storage/dexieStorageProvider.ts","lineNumber":147,"sourceCode":"    try {\n      await this.db.storage.delete(key);\n    } catch (error) {\n      console.error(`Failed to remove storage item (${key}):`, error);\n      throw new StorageError(`Failed to remove item: ${key}`, 'delete');\n    }\n  }\n\n  /**\n   * 清空所有存储\n   */\n  async clearAll(): Promise<void> {\n    await this.initialize();\n    \n    try {\n      await this.db.storage.clear();\n    } catch (error) {\n      console.error('Failed to clear storage:', error);\n      throw new StorageError('Failed to clear storage', 'clear');\n    }\n  }\n\n  /**\n   * 原子更新操作\n   * 使用 Dexie 的事务机制确保原子性，带重试和降级机制\n   */\n  async atomicUpdate<T>(\n    key: string,\n    updateFn: (currentValue: T | null) => T\n  ): Promise<void> {\n    await this.initialize();\n\n    // 获取键级别的锁\n    const lockKey = `atomic_${key}`;\n    if (this.keyLocks.has(lockKey)) {\n      await this.keyLocks.get(lockKey);\n    }","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/storage/dexieStorageProvider.ts#L129-L165","documentation":"StorageError with code 'clear' thrown by DexieStorageProvider.clearAll when db.storage.clear() rejects. Like the other Dexie wrappers, it indicates the connection is closed, blocked by a version-change transaction, or IndexedDB is unavailable/corrupted.","triggerScenarios":"Calling clearAll during a pending version upgrade in another tab, after db.close(), or in a context where IndexedDB is blocked (private mode, corrupted database file).","commonSituations":"'Reset all data' features failing because a stale tab holds the old DB version; running cleanup after the storage layer was disposed; incognito environments.","solutions":["Check the logged underlying error (console.error 'Failed to clear storage:')","Close other app tabs / ensure no pending version upgrade, then retry clearAll","If the DB is corrupt, delete the database (Dexie.delete(dbName)) and let the app recreate it"],"exampleFix":"// before\nawait provider.clearAll();\n\n// after\ntry { await provider.clearAll(); }\ncatch (e) {\n  if (e instanceof StorageError && e.code === 'clear') {\n    await provider.db.delete().then(() => provider.initialize()); // recreate\n  } else throw e;\n}","handlingStrategy":"fallback","validationCode":"if (!provider.db.isOpen()) await provider.db.open();","typeGuard":"const isStorageClearError = (e: unknown): e is StorageError =>\n  e instanceof StorageError && (e as StorageError).code === 'clear';","tryCatchPattern":"try { await provider.clearAll(); } catch (e) { if (isStorageClearError(e)) { await provider.db.delete(); await provider.initialize(); } else throw e; }","preventionTips":["Close other app tabs before destructive reset operations","Wrap 'reset data' UX with confirmation and a database-recreation fallback","Test clear flows in private/incognito mode where IndexedDB is restricted"],"tags":["storage","indexeddb","dexie","clear"],"backgroundTag":"indexeddb-operation-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}