{"record":{"id":"7917b9cb1f46b2e2","repo":"linshenkx/prompt-optimizer","slug":"failed-to-get-favorites-errormessage","errorCode":null,"errorMessage":"Failed to get favorites: ${errorMessage}","messagePattern":"Failed to get favorites: (.+?)","errorType":"exception","errorClass":"FavoriteStorageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":403,"sourceCode":"          return aValue > bValue ? 1 : -1;\n        } else {\n          return aValue < bValue ? 1 : -1;\n        }\n      });\n\n      // 分页\n      if (options.offset) {\n        favoritesList = favoritesList.slice(options.offset);\n      }\n\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);","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L385-L421","documentation":"Generic wrapper thrown by getFavorites when listing/filtering favorites fails at the storage layer; the original error message is appended. Affects all consumers: favorites getter, allFavorites, searchFavorites, exportFavorites.","triggerScenarios":"Any getFavorites call (with optional category/tag filters, search, limit) whose underlying storage read throws — corrupted store, read I/O error, or malformed persisted records.","commonSituations":"Store file corrupted after crash; unreadable data directory; partially migrated schema causing record deserialization errors; export attempted on a damaged store.","solutions":["Inspect the appended message for the underlying read error","Back up and restore or reset the favorites store if corrupted","Ensure the data directory is readable and the store schema matches the current version","Export favorites regularly so a store reset is recoverable"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":"const isGetFavoritesFailure = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError && e.message.startsWith('Failed to get favorites:');","tryCatchPattern":"try { return await manager.getFavorites(opts); } catch (e) { if (isGetFavoritesFailure(e)) { log.error(e.message); return lastKnownFavorites ?? []; } throw e; }","preventionTips":["Cache the last successful favorites list for degraded UI","Monitor storage read errors in main-process logs","Export favorites periodically so a corrupted store is recoverable"],"tags":["favorite","storage","read","wrapper"],"backgroundTag":"persistent-storage-read-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}