{"record":{"id":"19fd0bf9848b4ff4","repo":"linshenkx/prompt-optimizer","slug":"prompt-asset-is-not-available-for-this-favorite","errorCode":null,"errorMessage":"Prompt asset is not available for this favorite","messagePattern":"Prompt asset is not available for this favorite","errorType":"validation","errorClass":"FavoriteValidationError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":488,"sourceCode":"\n  async setFavoritePromptAssetCurrentVersion(id: string, versionId: string): Promise<void> {\n    await this.ensureInitialized();\n\n    try {\n      await this.storageProvider.updateData(this.STORAGE_KEYS.FAVORITES, (favorites: FavoritePrompt[] | null) => {\n        const favoritesList = favorites || [];\n        const index = favoritesList.findIndex(f => f.id === id);\n        if (index === -1) {\n          throw new FavoriteNotFoundError(id);\n        }\n\n        const currentFavorite = favoritesList[index];\n        const metadata = currentFavorite.metadata && typeof currentFavorite.metadata === 'object'\n          ? { ...currentFavorite.metadata }\n          : {};\n        const promptAsset = isPromptAsset(metadata.promptAsset) ? metadata.promptAsset : null;\n        if (!promptAsset) {\n          throw new FavoriteValidationError('Prompt asset is not available for this favorite');\n        }\n\n        const now = Date.now();\n        const switched = switchPromptAssetCurrentVersion(promptAsset, versionId, now);\n        if (!switched) {\n          throw new FavoriteValidationError(`Prompt asset version not found: ${versionId}`);\n        }\n\n        const nextFavorite: FavoritePrompt = {\n          ...currentFavorite,\n          content: switched.content,\n          updatedAt: now,\n          metadata: {\n            ...metadata,\n            promptAsset: switched.promptAsset,\n          },\n        };\n        assertFavoriteFitsItemBudget(nextFavorite);","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L470-L506","documentation":"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.","triggerScenarios":"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.","commonSituations":"Old favorites created before prompt-asset support; imports from other tools lacking asset metadata; manual edits to storage that broke the metadata object shape.","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"],"exampleFix":"// before\nawait manager.setFavoritePromptAssetCurrentVersion(id, versionId);\n// after\nconst fav = await manager.getFavorite(id);\nconst asset = fav.metadata?.promptAsset;\nif (isPromptAsset(asset)) await manager.setFavoritePromptAssetCurrentVersion(id, versionId);","handlingStrategy":"type-guard","validationCode":"const fav = await manager.getFavorite(id);\nif (!isPromptAsset(fav.metadata?.promptAsset)) return;","typeGuard":"import { isPromptAsset } from '<favorite-asset-module>';\nfunction hasPromptAsset(fav: FavoritePrompt): boolean {\n  return !!fav.metadata && isPromptAsset((fav.metadata as any).promptAsset);\n}","tryCatchPattern":"try { await manager.setFavoritePromptAssetCurrentVersion(id, versionId); }\ncatch (e) {\n  if (e instanceof FavoriteValidationError) { /* favorite has no versioned asset */ return; }\n  throw e;\n}","preventionTips":["Only show version-switch UI when isPromptAsset passes","Recreate asset metadata for legacy favorites before version operations"],"tags":["prompt-asset","validation","metadata"],"backgroundTag":"schema-validation-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}