linshenkx/prompt-optimizer · error · FavoriteStorageError
Failed to add category: ${errorMessage}
Error message
Failed to add category: ${errorMessage} What it means
Generic storage-layer wrapper thrown by FavoriteManager.addCategory when the underlying storageProvider.updateData call fails for a non-FavoriteError reason (I/O failure, serialization error, quota exceeded, provider misconfiguration).
Source
Thrown at packages/core/src/services/favorite/manager.ts:687
try {
await this.storageProvider.updateData(this.STORAGE_KEYS.CATEGORIES, (categories: FavoriteCategory[] | null) => {
const categoriesList = categories || [];
// 检查是否已存在同名分类
const existing = categoriesList.find(c => c.name === category.name);
if (existing) {
throw new FavoriteValidationError(`Category already exists: ${category.name}`);
}
return [...categoriesList, newCategory];
});
return id;
} catch (error) {
if (error instanceof FavoriteError) {
throw error;
}
const errorMessage = error instanceof Error ? error.message : String(error);
throw new FavoriteStorageError(`Failed to add category: ${errorMessage}`);
}
}
async updateCategory(id: string, updates: Partial<FavoriteCategory>): Promise<void> {
try {
await this.storageProvider.updateData(this.STORAGE_KEYS.CATEGORIES, (categories: FavoriteCategory[] | null) => {
const categoriesList = categories || [];
const index = categoriesList.findIndex(c => c.id === id);
if (index === -1) {
throw new FavoriteCategoryNotFoundError(id);
}
categoriesList[index] = {
...categoriesList[index],
...updates
};
return categoriesList;View on GitHub (pinned to 3e677b1d9f)
Solutions
- Inspect error.cause/original message to identify the real storage failure
- Free up storage or increase quota (clear old data, reduce export size)
- Verify the storage provider is properly initialized and accessible before manager operations
- If corruption is suspected, export favorites, reset storage, and re-import
Defensive patterns
Strategy: try-catch
Type guard
const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;
Try / catch
try { await manager.addCategory(cat); } catch (e) { if (e instanceof FavoriteStorageError) { /* inspect e.cause, surface storage issue */ } throw e; } Prevention
- Check storage availability before bulk operations
- Monitor storage quota during imports
When it happens
Trigger: Storage provider throws (disk write failure, localStorage quota exceeded, IndexedDB unavailable), or the update callback throws a non-FavoriteError; called directly or via ensureDefaultCategories/importFavorites.
Common situations: Browser private mode with blocked storage; full localStorage quota after large imports; a custom storage provider that doesn't implement updateData correctly; storage schema corruption.
Related errors
- Failed to add favorite: ${errorMessage}
- Failed to update category: ${errorMessage}
- Failed to delete category: ${errorMessage}
- Failed to get category usage: ${errorMessage}
- STORAGE_ERROR
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/8c3f77ac6aeae997.
Report an issue: GitHub.