{"record":{"id":"7ef70d31f03bc058","repo":"linshenkx/prompt-optimizer","slug":"failed-to-add-favorite-errormessage","errorCode":null,"errorMessage":"Failed to add favorite: ${errorMessage}","messagePattern":"Failed to add favorite: (.+?)","errorType":"exception","errorClass":"FavoriteStorageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":332,"sourceCode":"      await this.storageProvider.updateData(this.STORAGE_KEYS.FAVORITES, (favorites: FavoritePrompt[] | null) => {\n        const favoritesList = favorites || [];\n        // 🔧 移除重复内容检查 - 允许收藏相同内容但属性不同的提示词\n        // 用户可能需要��同一内容设置不同的标题、分类、标签等\n        const nextFavoritesList = [...favoritesList, newFavorite];\n        assertFavoritesPayloadWithinBudget(nextFavoritesList, {\n          warnOnSoftLimit: true,\n        });\n        return nextFavoritesList;\n      });\n\n      await this.updateStats();\n      return id;\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 add favorite: ${errorMessage}`);\n    }\n  }\n\n  async getFavorites(options: {\n    categoryId?: string;\n    tags?: string[];\n    keyword?: string;\n    sortBy?: 'createdAt' | 'updatedAt' | 'useCount' | 'title';\n    sortOrder?: 'asc' | 'desc';\n    limit?: number;\n    offset?: number;\n  } = {}): Promise<FavoritePrompt[]> {\n    await this.ensureInitialized();\n\n    try {\n      const favorites = await this.storageProvider.getItem(this.STORAGE_KEYS.FAVORITES);\n      let favoritesList: FavoritePrompt[] = favorites ? JSON.parse(favorites) : [];\n","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L314-L350","documentation":"Generic wrapper thrown by addFavorite when the underlying storage operation fails with a non-FavoriteError; the original message is appended. FavoriteErrors raised inside are rethrown unchanged.","triggerScenarios":"Storage write failure (file/DB error), serialization failure, or any unexpected exception during addFavorite execution that isn't already a FavoriteError.","commonSituations":"Corrupted or locked favorites store; permissions problems in the data directory; disk full; store not writable after a migration.","solutions":["Read the appended errorMessage to identify the underlying cause","Check write permissions/disk space for the favorites data directory","If the store is corrupted, back up and reset it, then re-import favorites","Verify the manager was initialized with a valid storage configuration"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isAddFavoriteFailure = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError && e.message.startsWith('Failed to add favorite:');","tryCatchPattern":"try { return await manager.addFavorite(fav); } catch (e) { if (isAddFavoriteFailure(e)) { log.error(e.message); notifyUser('Could not save favorite'); return null; } throw e; }","preventionTips":["Keep the data directory writable and backed up","Wrap addFavorite at the UI boundary with user-facing feedback","Log the appended underlying message for diagnosis"],"tags":["favorite","storage","io","wrapper"],"backgroundTag":"persistent-storage-write-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}