linshenkx/prompt-optimizer · error · FavoriteValidationError
Cannot delete the current prompt asset version
Error message
Cannot delete the current prompt asset version
What it means
Thrown when deleteFavoritePromptAssetVersion is asked to remove the version currently marked as the prompt asset's active version (promptAsset.currentVersionId === versionId). The library keeps currentVersionId pointing at a live version, so the active version cannot be deleted directly; you must switch to another version first.
Source
Thrown at packages/core/src/services/favorite/manager.ts:549
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');
}
if (promptAsset.versions.length <= 1) {
throw new FavoriteValidationError('Cannot delete the last prompt asset version');
}
if (promptAsset.currentVersionId === versionId) {
throw new FavoriteValidationError('Cannot delete the current prompt asset version');
}
const now = Date.now();
const nextPromptAsset = deletePromptAssetVersion(promptAsset, versionId, now);
if (!nextPromptAsset) {
throw new FavoriteValidationError(`Prompt asset version not found: ${versionId}`);
}
const nextFavorite: FavoritePrompt = {
...currentFavorite,
updatedAt: now,
metadata: {
...metadata,
promptAsset: nextPromptAsset,
},
};
assertFavoriteFitsItemBudget(nextFavorite);
View on GitHub (pinned to 3e677b1d9f)
Solutions
- Before deleting, switch the current version (e.g. via the manager's update/restore API so currentVersionId points elsewhere), then delete the old version
- Guard the delete action with currentVersionId !== versionId in the UI
- Catch FavoriteValidationError and inform the user the active version cannot be removed
Example fix
// before
await manager.deleteFavoritePromptAssetVersion(favId, versionId);
// after
const fav = await manager.getFavorite(favId);
const asset = fav.metadata.promptAsset;
if (asset && asset.currentVersionId === versionId) {
// switch to another version first, or block the action
throw new Error('Switch to another version before deleting the current one');
}
await manager.deleteFavoritePromptAssetVersion(favId, versionId); Defensive patterns
Strategy: validation
Validate before calling
const fav = await manager.getFavorite(favId);
const asset = fav.metadata.promptAsset;
if (asset?.currentVersionId === versionId) { /* block: switch version first */ } Type guard
const isCurrentVersion = (asset: { currentVersionId: string }, id: string) => asset.currentVersionId === id; Try / catch
try { await manager.deleteFavoritePromptAssetVersion(id, vId); } catch (e) { if (e instanceof FavoriteValidationError && /current/.test(e.message)) { /* prompt user to switch version */ } else throw e; } Prevention
- Mark the current version as non-deletable in the UI
- Switch currentVersionId before issuing delete
When it happens
Trigger: Calling deleteFavoritePromptAssetVersion(favoriteId, versionId) where versionId equals the asset's currentVersionId — typically the version shown/selected in the UI is the one the user tries to delete, even when other versions exist.
Common situations: A version-history UI that offers delete on the currently selected/active row; state desync where the UI's selected version id is stale relative to the stored currentVersionId; restoring an old version then trying to delete the previous current one.
Related errors
- Cannot delete the last prompt asset version
- Prompt asset is not available for this favorite
- Prompt asset version not found: ${versionId}
- Category already exists: ${category.name}
- Tag name cannot be empty
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/ddeaadf6e95e7725.
Report an issue: GitHub.