{"record":{"id":"5e717aa708d43837","repo":"linshenkx/prompt-optimizer","slug":"favorite-not-found-id","errorCode":null,"errorMessage":"Favorite not found: ${id}","messagePattern":"Favorite not found: (.+?)","errorType":"exception","errorClass":"FavoriteNotFoundError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":413,"sourceCode":"\n      if (options.limit) {\n        favoritesList = favoritesList.slice(0, options.limit);\n      }\n\n      return favoritesList;\n    } catch (error) {\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new FavoriteStorageError(`Failed to get favorites: ${errorMessage}`);\n    }\n  }\n\n  async getFavorite(id: string): Promise<FavoritePrompt> {\n    try {\n      const favorites = await this.getFavorites();\n      const favorite = favorites.find(f => f.id === id);\n\n      if (!favorite) {\n        throw new FavoriteNotFoundError(id);\n      }\n\n      return favorite;\n    } catch (error) {\n      if (error instanceof FavoriteError) {\n        throw error;\n      }\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new FavoriteStorageError(`Failed to get favorite details: ${errorMessage}`);\n    }\n  }\n\n  async updateFavorite(id: string, updates: Partial<FavoritePrompt>): Promise<void> {\n    await this.ensureInitialized();\n\n    try {\n      if (Object.prototype.hasOwnProperty.call(updates, 'metadata')) {\n        assertFavoriteMetadataHasNoInlineImages(updates.metadata);","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L395-L431","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nconst fav = await manager.getFavorite(someIdFromState);\n// after\nconst exists = (await manager.getFavorites()).some(f => f.id === someIdFromState);\nif (!exists) throw new Error(`stale favorite id: ${someIdFromState}`);\nconst fav = await manager.getFavorite(someIdFromState);","handlingStrategy":"try-catch","validationCode":"const exists = (await manager.getFavorites()).some(f => f.id === id);\nif (!exists) return null;","typeGuard":"function isFavoriteNotFoundError(e: unknown): e is FavoriteNotFoundError {\n  return e instanceof FavoriteNotFoundError;\n}","tryCatchPattern":"try {\n  const fav = await manager.getFavorite(id);\n} catch (e) {\n  if (e instanceof FavoriteNotFoundError) { /* drop stale id */ return; }\n  throw e;\n}","preventionTips":["Always source ids from a freshly fetched getFavorites() list","Drop persisted ids from UI state after any delete/export-import cycle"],"tags":["favorites","not-found","id-mismatch"],"backgroundTag":"entity-not-found","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}