linshenkx/prompt-optimizer · error · FavoriteStorageError
Failed to get favorites: ${errorMessage}
Error message
Failed to get favorites: ${errorMessage} What it means
Generic wrapper thrown by getFavorites when listing/filtering favorites fails at the storage layer; the original error message is appended. Affects all consumers: favorites getter, allFavorites, searchFavorites, exportFavorites.
Source
Thrown at packages/core/src/services/favorite/manager.ts:403
return aValue > bValue ? 1 : -1;
} else {
return aValue < bValue ? 1 : -1;
}
});
// 分页
if (options.offset) {
favoritesList = favoritesList.slice(options.offset);
}
if (options.limit) {
favoritesList = favoritesList.slice(0, options.limit);
}
return favoritesList;
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new FavoriteStorageError(`Failed to get favorites: ${errorMessage}`);
}
}
async getFavorite(id: string): Promise<FavoritePrompt> {
try {
const favorites = await this.getFavorites();
const favorite = favorites.find(f => f.id === id);
if (!favorite) {
throw new FavoriteNotFoundError(id);
}
return favorite;
} catch (error) {
if (error instanceof FavoriteError) {
throw error;
}
const errorMessage = error instanceof Error ? error.message : String(error);View on GitHub (pinned to 3e677b1d9f)
Solutions
- Inspect the appended message for the underlying read error
- Back up and restore or reset the favorites store if corrupted
- Ensure the data directory is readable and the store schema matches the current version
- Export favorites regularly so a store reset is recoverable
Defensive patterns
Strategy: fallback
Type guard
const isGetFavoritesFailure = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError && e.message.startsWith('Failed to get favorites:'); Try / catch
try { return await manager.getFavorites(opts); } catch (e) { if (isGetFavoritesFailure(e)) { log.error(e.message); return lastKnownFavorites ?? []; } throw e; } Prevention
- Cache the last successful favorites list for degraded UI
- Monitor storage read errors in main-process logs
- Export favorites periodically so a corrupted store is recoverable
When it happens
Trigger: Any getFavorites call (with optional category/tag filters, search, limit) whose underlying storage read throws — corrupted store, read I/O error, or malformed persisted records.
Common situations: Store file corrupted after crash; unreadable data directory; partially migrated schema causing record deserialization errors; export attempted on a damaged store.
Related errors
- Failed to add favorite: ${errorMessage}
- STORAGE_ERROR
- TAG_ERROR
- error.message || ''
- Failed to add category: ${errorMessage}
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/7917b9cb1f46b2e2.
Report an issue: GitHub.