linshenkx/prompt-optimizer · error · FavoriteStorageError
Failed to get statistics: ${errorMessage}
Error message
Failed to get statistics: ${errorMessage} What it means
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.
Source
Thrown at packages/core/src/services/favorite/manager.ts:771
throw error;
}
const errorMessage = error instanceof Error ? error.message : String(error);
throw new FavoriteStorageError(`Failed to delete category: ${errorMessage}`);
}
}
async getStats(): Promise<FavoriteStats> {
try {
const stats = await this.storageProvider.getItem(this.STORAGE_KEYS.STATS);
if (stats) {
return JSON.parse(stats);
}
// 如果没有缓存的统计数据,计算并缓存
return await this.updateStats();
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new FavoriteStorageError(`Failed to get statistics: ${errorMessage}`);
}
}
private async updateStats(): Promise<FavoriteStats> {
const favorites = await this.getFavorites();
const categories = await this.getCategories();
const categoryStats = categories.map(category => ({
categoryId: category.id,
categoryName: category.name,
count: favorites.filter(f => f.category === category.id).length
}));
const tagCounts = new Map<string, number>();
favorites.forEach(favorite => {
favorite.tags.forEach(tag => {
tagCounts.set(tag, (tagCounts.get(tag) || 0) + 1);
});View on GitHub (pinned to 3e677b1d9f)
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
Defensive patterns
Strategy: fallback
Type guard
const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;
Try / catch
try { return await manager.getStats(); } catch (e) { if (isFavoriteStorageError(e)) { /* fallback: compute counts from getFavorites() locally or show cached UI values */ } throw e; } Prevention
- Treat stats as derived data — always have a UI fallback
- Clear and rebuild stats cache on corruption
When it happens
Trigger: getItem(STATS) fails, or updateStats→getFavorites/getCategories throws (favorite-level storage errors get re-wrapped here).
Common situations: Corrupted stats cache; underlying favorites storage unreadable; provider initialization issues.
Related errors
- Failed to get tags: ${errorMessage}
- Failed to get favorites: ${errorMessage}
- Failed to delete favorite prompt asset version: ${errorMessa
- Failed to add category: ${errorMessage}
- Failed to update category: ${errorMessage}
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/82d268a2f96977fe.
Report an issue: GitHub.