linshenkx/prompt-optimizer · error · FavoriteStorageError
Failed to add favorite: ${errorMessage}
Error message
Failed to add favorite: ${errorMessage} What it means
Generic wrapper thrown by addFavorite when the underlying storage operation fails with a non-FavoriteError; the original message is appended. FavoriteErrors raised inside are rethrown unchanged.
Source
Thrown at packages/core/src/services/favorite/manager.ts:332
await this.storageProvider.updateData(this.STORAGE_KEYS.FAVORITES, (favorites: FavoritePrompt[] | null) => {
const favoritesList = favorites || [];
// 🔧 移除重复内容检查 - 允许收藏相同内容但属性不同的提示词
// 用户可能需要��同一内容设置不同的标题、分类、标签等
const nextFavoritesList = [...favoritesList, newFavorite];
assertFavoritesPayloadWithinBudget(nextFavoritesList, {
warnOnSoftLimit: true,
});
return nextFavoritesList;
});
await this.updateStats();
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 favorite: ${errorMessage}`);
}
}
async getFavorites(options: {
categoryId?: string;
tags?: string[];
keyword?: string;
sortBy?: 'createdAt' | 'updatedAt' | 'useCount' | 'title';
sortOrder?: 'asc' | 'desc';
limit?: number;
offset?: number;
} = {}): Promise<FavoritePrompt[]> {
await this.ensureInitialized();
try {
const favorites = await this.storageProvider.getItem(this.STORAGE_KEYS.FAVORITES);
let favoritesList: FavoritePrompt[] = favorites ? JSON.parse(favorites) : [];
View on GitHub (pinned to 3e677b1d9f)
Solutions
- Read the appended errorMessage to identify the underlying cause
- Check write permissions/disk space for the favorites data directory
- If the store is corrupted, back up and reset it, then re-import favorites
- Verify the manager was initialized with a valid storage configuration
Defensive patterns
Strategy: try-catch
Type guard
const isAddFavoriteFailure = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError && e.message.startsWith('Failed to add favorite:'); Try / catch
try { return await manager.addFavorite(fav); } catch (e) { if (isAddFavoriteFailure(e)) { log.error(e.message); notifyUser('Could not save favorite'); return null; } throw e; } Prevention
- Keep the data directory writable and backed up
- Wrap addFavorite at the UI boundary with user-facing feedback
- Log the appended underlying message for diagnosis
When it happens
Trigger: Storage write failure (file/DB error), serialization failure, or any unexpected exception during addFavorite execution that isn't already a FavoriteError.
Common situations: Corrupted or locked favorites store; permissions problems in the data directory; disk full; store not writable after a migration.
Related errors
- STORAGE_ERROR
- Failed to get favorites: ${errorMessage}
- Failed to add category: ${errorMessage}
- TAG_ERROR
- error.message || ''
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/7ef70d31f03bc058.
Report an issue: GitHub.