{"record":{"id":"a20d3222d28a69ed","repo":"linshenkx/prompt-optimizer","slug":"failed-to-merge-tags-errormessage","errorCode":null,"errorMessage":"Failed to merge tags: ${errorMessage}","messagePattern":"Failed to merge tags: (.+?)","errorType":"exception","errorClass":"FavoriteStorageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":1104,"sourceCode":"\n          // 如果存在源标签,添加目标标签(如果不存在)\n          if (hasSourceTag) {\n            if (!favorite.tags.includes(targetTag)) {\n              favorite.tags.push(targetTag);\n            }\n            favorite.updatedAt = Date.now();\n            affectedCount++;\n          }\n        });\n\n        return favoritesList;\n      });\n\n      await this.updateStats();\n      return affectedCount;\n    } catch (error) {\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new FavoriteStorageError(`Failed to merge tags: ${errorMessage}`);\n    }\n  }\n\n  async deleteTag(tag: string): Promise<number> {\n    if (!tag) {\n      throw new FavoriteValidationError('Tag name cannot be empty');\n    }\n\n    let affectedCount = 0;\n\n    try {\n      // 1. 从独立标签中删除\n      await this.storageProvider.updateData(this.STORAGE_KEYS.TAGS, (tags: FavoriteTag[] | null) => {\n        const tagsList = tags || [];\n        return tagsList.filter(t => t.tag !== tag);\n      });\n\n      // 2. 从所有收藏项中删除","sourceCodeStart":1086,"sourceCodeEnd":1122,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L1086-L1122","documentation":"FavoriteStorageError thrown by mergeTags when any of its multiple storage writes (removing source tags from the tag library, adding the target, rewriting favorites' tags) or the final updateStats fails.","triggerScenarios":"Quota/I/O failure during the multi-step merge; malformed tag data causing the rewrite callbacks to throw.","commonSituations":"Merging large numbers of tags exceeding quota; interrupted writes leaving partially merged state; corrupted favorite tag arrays.","solutions":["Inspect the wrapped message for the failing step","Verify data consistency after a failed merge (tag library vs favorites) and repair","Free storage or merge fewer tags at a time"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;","tryCatchPattern":"try { return await manager.mergeTags(sources, target); } catch (e) { if (isFavoriteStorageError(e)) { /* audit tag library + favorites for partial merge, repair, optionally retry */ } throw e; }","preventionTips":["Merge in smaller batches","Verify consistency after failed merges since merge is multi-write"],"tags":["storage","tags","merge","favorites"],"backgroundTag":"storage-write-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}