{"record":{"id":"82d268a2f96977fe","repo":"linshenkx/prompt-optimizer","slug":"failed-to-get-statistics-errormessage","errorCode":null,"errorMessage":"Failed to get statistics: ${errorMessage}","messagePattern":"Failed to get statistics: (.+?)","errorType":"exception","errorClass":"FavoriteStorageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":771,"sourceCode":"        throw error;\n      }\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new FavoriteStorageError(`Failed to delete category: ${errorMessage}`);\n    }\n  }\n\n  async getStats(): Promise<FavoriteStats> {\n    try {\n      const stats = await this.storageProvider.getItem(this.STORAGE_KEYS.STATS);\n      if (stats) {\n        return JSON.parse(stats);\n      }\n\n      // 如果没有缓存的统计数据，计算并缓存\n      return await this.updateStats();\n    } catch (error) {\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new FavoriteStorageError(`Failed to get statistics: ${errorMessage}`);\n    }\n  }\n\n  private async updateStats(): Promise<FavoriteStats> {\n    const favorites = await this.getFavorites();\n    const categories = await this.getCategories();\n\n    const categoryStats = categories.map(category => ({\n      categoryId: category.id,\n      categoryName: category.name,\n      count: favorites.filter(f => f.category === category.id).length\n    }));\n\n    const tagCounts = new Map<string, number>();\n    favorites.forEach(favorite => {\n      favorite.tags.forEach(tag => {\n        tagCounts.set(tag, (tagCounts.get(tag) || 0) + 1);\n      });","sourceCodeStart":753,"sourceCodeEnd":789,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L753-L789","documentation":"FavoriteStorageError thrown by getStats when reading cached stats from storage or when recomputing them via updateStats fails. Note this wrapper converts even underlying FavoriteErrors into a generic storage message.","triggerScenarios":"getItem(STATS) fails, or updateStats→getFavorites/getCategories throws (favorite-level storage errors get re-wrapped here).","commonSituations":"Corrupted stats cache; underlying favorites storage unreadable; provider initialization issues.","solutions":["Clear the cached stats key and let stats recompute","Verify getFavorites()/getCategories() work directly to isolate the failing dataset","Check provider connectivity/health if using remote storage"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":"const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;","tryCatchPattern":"try { return await manager.getStats(); } catch (e) { if (isFavoriteStorageError(e)) { /* fallback: compute counts from getFavorites() locally or show cached UI values */ } throw e; }","preventionTips":["Treat stats as derived data — always have a UI fallback","Clear and rebuild stats cache on corruption"],"tags":["storage","stats","favorites","read"],"backgroundTag":"storage-read-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}