linshenkx/prompt-optimizer · error · FavoriteValidationError

Prompt asset version not found: ${versionId}

Error message

Prompt asset version not found: ${versionId}

What it means

FavoriteValidationError thrown when switchPromptAssetCurrentVersion returns falsy because versionId does not match any version in the favorite's prompt asset versions list. The id must exist and the asset must be present; only the version reference is wrong.

Source

Thrown at packages/core/src/services/favorite/manager.ts:494

        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);

        favoritesList[index] = nextFavorite;
        assertFavoritesPayloadWithinBudget(favoritesList, {
          warnOnSoftLimit: true,
        });

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Re-read the favorite and offer only asset.versions[].id as selectable version ids
  2. Remove deleted version ids from persisted UI state
  3. Verify versionId format matches the generated version ids exactly

Example fix

// before
await manager.setFavoritePromptAssetCurrentVersion(id, pickedVersionId);
// after
const fav = await manager.getFavorite(id);
const asset = fav.metadata?.promptAsset;
if (isPromptAsset(asset) && asset.versions.some(v => v.id === pickedVersionId)) {
  await manager.setFavoritePromptAssetCurrentVersion(id, pickedVersionId);
}
Defensive patterns

Strategy: validation

Validate before calling

const fav = await manager.getFavorite(id);
const asset = fav.metadata?.promptAsset;
if (!isPromptAsset(asset) || !asset.versions.some(v => v.id === versionId)) return;

Type guard

function isValidVersionId(asset: PromptAsset, versionId: string): boolean {
  return asset.versions.some(v => v.id === versionId);
}

Try / catch

try { await manager.setFavoritePromptAssetCurrentVersion(id, versionId); }
catch (e) {
  if (e instanceof FavoriteValidationError) { /* refresh version list */ }
  else throw e;
}

Prevention

When it happens

Trigger: Calling setFavoritePromptAssetCurrentVersion with a versionId that was deleted, belongs to another favorite's asset, or is a stale/garbled identifier.

Common situations: Version list refreshed after deletions while UI kept an old versionId; copy-paste of version ids between favorites.

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


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/5b3284574d147473. Report an issue: GitHub.