{"record":{"id":"c643302c14c31fc3","repo":"linshenkx/prompt-optimizer","slug":"failed-to-get-tags-errormessage","errorCode":null,"errorMessage":"Failed to get tags: ${errorMessage}","messagePattern":"Failed to get tags: (.+?)","errorType":"exception","errorClass":"FavoriteStorageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":918,"sourceCode":"    return tagCounts;\n  }\n\n  async getAllTags(): Promise<Array<{ tag: string; count: number }>> {\n    try {\n      const tagCounts = await this.computeTagCounts();\n\n      // 返回排序后的结果（使用次数降序，相同次数按标签名升序）\n      return Array.from(tagCounts.entries())\n        .map(([tag, count]) => ({ tag, count }))\n        .sort((a, b) => {\n          if (b.count !== a.count) {\n            return b.count - a.count; // 按使用次数降序\n          }\n          return TagTypeConverter.compareTagNames(a.tag, b.tag); // 相同次数按标签名升序\n        });\n    } catch (error) {\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new FavoriteStorageError(`Failed to get tags: ${errorMessage}`);\n    }\n  }\n\n  async addTag(tag: string): Promise<void> {\n    await this.ensureInitialized();\n\n    const trimmedTag = tag.trim();\n    if (!trimmedTag) {\n      throw new FavoriteValidationError('Tag name cannot be empty');\n    }\n\n    let added = false;\n\n    try {\n      await this.storageProvider.updateData(this.STORAGE_KEYS.TAGS, (tags: FavoriteTag[] | null) => {\n        const tagsList = tags || [];\n\n        // 检查是否已存在","sourceCodeStart":900,"sourceCodeEnd":936,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L900-L936","documentation":"FavoriteStorageError thrown by getTags when reading the independent tag library from storage or while sorting/transforming tags fails.","triggerScenarios":"storageProvider.getItem/updateData for TAGS failing; tag entries with unexpected shapes causing compare/convert functions to throw during sorting.","commonSituations":"Corrupted tag store after partial imports; custom or legacy tag data missing fields; provider read failures.","solutions":["Inspect the wrapped message; if it mentions tag conversion, audit stored tag entries for malformed fields","Rebuild the tag library from favorites if corrupted","Verify storage provider health"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":"const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;","tryCatchPattern":"try { return await manager.getTags(); } catch (e) { if (isFavoriteStorageError(e)) { return []; /* derive tags from favorites as fallback */ } throw e; }","preventionTips":["Keep tag entries well-formed (name + count fields)","Derive tag lists defensively in read-only views"],"tags":["storage","tags","favorites","read"],"backgroundTag":"storage-read-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}