{"record":{"id":"32d877e6b0f031c9","repo":"linshenkx/prompt-optimizer","slug":"failed-to-export-favorites-errormessage","errorCode":null,"errorMessage":"Failed to export favorites: ${errorMessage}","messagePattern":"Failed to export favorites: (.+?)","errorType":"exception","errorClass":"FavoriteImportExportError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":865,"sourceCode":"      } else {\n        favorites = await this.getFavorites();\n      }\n\n      const categories = await this.getCategories();\n      const tags = await this.getAllIndependentTags();\n\n      const exportData = {\n        version: '1.0',\n        exportDate: new Date().toISOString(),\n        favorites,\n        categories,\n        tags  // 导出独立标签库（包含所有标签：使用中的 + 预创建的）\n      };\n\n      return JSON.stringify(exportData, null, 2);\n    } catch (error) {\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new FavoriteImportExportError(\n        `Failed to export favorites: ${errorMessage}`,\n        error instanceof Error ? error : undefined\n      );\n    }\n  }\n\n  /**\n   * 计算标签使用统计\n   * @private\n   * @returns 包含标签名和使用次数的 Map\n   */\n  private async computeTagCounts(): Promise<Map<string, number>> {\n    // 1. 获取独立标签\n    const storedTags = await this.storageProvider.getItem(this.STORAGE_KEYS.TAGS);\n    const independentTags: FavoriteTag[] = storedTags ? JSON.parse(storedTags) : [];\n\n    // 2. 统计收藏项中使用的标签\n    const favorites = await this.getFavorites();","sourceCodeStart":847,"sourceCodeEnd":883,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L847-L883","documentation":"FavoriteImportExportError thrown by exportFavorites when serializing the export payload (favorites, categories, tags) to JSON fails or any preceding read fails. The original error is attached as the cause.","triggerScenarios":"JSON.stringify throwing on circular references in favorite data; getFavorites/getCategories/getTags failing during export assembly.","commonSituations":"User-defined metadata attached to favorites containing circular structures; storage read failures; very large datasets hitting memory limits.","solutions":["Inspect error.cause for the underlying failure","Sanitize custom metadata (strip circular refs) before storing on favorites","Export in smaller batches if memory is the issue"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isImportExportError = (e: unknown): e is FavoriteImportExportError => e instanceof FavoriteImportExportError;","tryCatchPattern":"try { return await manager.exportFavorites(); } catch (e) { if (isImportExportError(e) && e.cause instanceof TypeError) { /* strip circular refs from metadata and retry */ } throw e; }","preventionTips":["Never store circular structures in favorite metadata","Keep custom metadata JSON-safe"],"tags":["export","serialization","favorites","io"],"backgroundTag":"serialization-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}