linshenkx/prompt-optimizer · error · FavoriteNotFoundError
Favorite not found: ${id}
Error message
Favorite not found: ${id} What it means
Thrown by FavoriteManager.getFavorite when no stored favorite matches the given id. The manager loads the full favorites list from the storage provider and does a strict id comparison, so any id that is not currently persisted (or belongs to a different data set) triggers FavoriteNotFoundError.
Source
Thrown at packages/core/src/services/favorite/manager.ts:413
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);
throw new FavoriteStorageError(`Failed to get favorite details: ${errorMessage}`);
}
}
async updateFavorite(id: string, updates: Partial<FavoritePrompt>): Promise<void> {
await this.ensureInitialized();
try {
if (Object.prototype.hasOwnProperty.call(updates, 'metadata')) {
assertFavoriteMetadataHasNoInlineImages(updates.metadata);View on GitHub (pinned to 3e677b1d9f)
Solutions
- Verify the id exists first via getFavorites().some(f => f.id === id)
- Re-fetch the favorites list to refresh stale ids held in UI state
- If the favorite was deleted intentionally, remove/ignore the dangling id instead of retrying
- Check that the correct storage provider/workspace is initialized before calling
Example fix
// before
const fav = await manager.getFavorite(someIdFromState);
// after
const exists = (await manager.getFavorites()).some(f => f.id === someIdFromState);
if (!exists) throw new Error(`stale favorite id: ${someIdFromState}`);
const fav = await manager.getFavorite(someIdFromState); Defensive patterns
Strategy: try-catch
Validate before calling
const exists = (await manager.getFavorites()).some(f => f.id === id); if (!exists) return null;
Type guard
function isFavoriteNotFoundError(e: unknown): e is FavoriteNotFoundError {
return e instanceof FavoriteNotFoundError;
} Try / catch
try {
const fav = await manager.getFavorite(id);
} catch (e) {
if (e instanceof FavoriteNotFoundError) { /* drop stale id */ return; }
throw e;
} Prevention
- Always source ids from a freshly fetched getFavorites() list
- Drop persisted ids from UI state after any delete/export-import cycle
When it happens
Trigger: Calling getFavorite(id), or incrementUseCount(id)/exportFavorites() paths that resolve favorites by id, with an id that is absent from stored favorites (deleted earlier, never created, stale id from an old export or another workspace).
Common situations: Using a persisted favorite id after the favorite was deleted; mixing ids between environments; storage was reset/cleared; typo or truncated id passed from UI state.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Category not found: ${id}
- Evaluation model key must not be empty.
- Function mode must not be empty.
- Sub mode must not be empty.
- ${modelKey}
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/5e717aa708d43837.
Report an issue: GitHub.