linshenkx/prompt-optimizer · error · FavoriteValidationError
Prompt asset is not available for this favorite
Error message
Prompt asset is not available for this favorite
What it means
FavoriteValidationError indicating the favorite exists but its metadata.promptAsset is missing or does not pass isPromptAsset validation, so there is no versioned asset to switch. Favorites created as plain text (no asset metadata) will always trigger this.
Source
Thrown at packages/core/src/services/favorite/manager.ts:488
async setFavoritePromptAssetCurrentVersion(id: string, versionId: string): Promise<void> {
await this.ensureInitialized();
try {
await this.storageProvider.updateData(this.STORAGE_KEYS.FAVORITES, (favorites: FavoritePrompt[] | null) => {
const favoritesList = favorites || [];
const index = favoritesList.findIndex(f => f.id === id);
if (index === -1) {
throw new FavoriteNotFoundError(id);
}
const currentFavorite = favoritesList[index];
const metadata = currentFavorite.metadata && typeof currentFavorite.metadata === 'object'
? { ...currentFavorite.metadata }
: {};
const promptAsset = isPromptAsset(metadata.promptAsset) ? metadata.promptAsset : null;
if (!promptAsset) {
throw new FavoriteValidationError('Prompt asset is not available for this favorite');
}
const now = Date.now();
const switched = switchPromptAssetCurrentVersion(promptAsset, versionId, now);
if (!switched) {
throw new FavoriteValidationError(`Prompt asset version not found: ${versionId}`);
}
const nextFavorite: FavoritePrompt = {
...currentFavorite,
content: switched.content,
updatedAt: now,
metadata: {
...metadata,
promptAsset: switched.promptAsset,
},
};
assertFavoriteFitsItemBudget(nextFavorite);View on GitHub (pinned to 3e677b1d9f)
Solutions
- Guard the call by checking metadata.promptAsset with isPromptAsset first
- If the favorite should have an asset, re-link/recreate the prompt asset metadata before switching versions
- Skip version operations for plain-text favorites
Example fix
// before await manager.setFavoritePromptAssetCurrentVersion(id, versionId); // after const fav = await manager.getFavorite(id); const asset = fav.metadata?.promptAsset; if (isPromptAsset(asset)) await manager.setFavoritePromptAssetCurrentVersion(id, versionId);
Defensive patterns
Strategy: type-guard
Validate before calling
const fav = await manager.getFavorite(id); if (!isPromptAsset(fav.metadata?.promptAsset)) return;
Type guard
import { isPromptAsset } from '<favorite-asset-module>';
function hasPromptAsset(fav: FavoritePrompt): boolean {
return !!fav.metadata && isPromptAsset((fav.metadata as any).promptAsset);
} Try / catch
try { await manager.setFavoritePromptAssetCurrentVersion(id, versionId); }
catch (e) {
if (e instanceof FavoriteValidationError) { /* favorite has no versioned asset */ return; }
throw e;
} Prevention
- Only show version-switch UI when isPromptAsset passes
- Recreate asset metadata for legacy favorites before version operations
When it happens
Trigger: Calling setFavoritePromptAssetCurrentVersion on a favorite that was never linked to a prompt asset, whose metadata is corrupt, or whose promptAsset field has the wrong shape.
Common situations: Old favorites created before prompt-asset support; imports from other tools lacking asset metadata; manual edits to storage that broke the metadata object shape.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Prompt asset version not found: ${versionId}
- Cannot delete the last prompt asset version
- Cannot delete the current prompt asset version
- Favorite metadata cannot contain inline image data URLs (${p
- CONTEXT_ERROR_CODES.STORAGE_ERROR
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/19fd0bf9848b4ff4.
Report an issue: GitHub.