{"record":{"id":"df6989132546b367","repo":"linshenkx/prompt-optimizer","slug":"failed-to-rename-tag-errormessage","errorCode":null,"errorMessage":"Failed to rename tag: ${errorMessage}","messagePattern":"Failed to rename tag: (.+?)","errorType":"exception","errorClass":"FavoriteStorageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":1036,"sourceCode":"\n          // 添加新标签(如果不存在)\n          const hasNewTag = tagsList.some(t => t.tag === newTag);\n          if (!hasNewTag) {\n            tagsList.push({\n              tag: newTag,\n              createdAt: Date.now()\n            });\n          }\n\n          return tagsList;\n        });\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 rename tag: ${errorMessage}`);\n    }\n  }\n\n  async mergeTags(sourceTags: string[], targetTag: string): Promise<number> {\n    if (!sourceTags || sourceTags.length === 0) {\n      throw new FavoriteValidationError('Source tag list cannot be empty');\n    }\n\n    if (!targetTag) {\n      throw new FavoriteValidationError('Target tag 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 || [];","sourceCodeStart":1018,"sourceCodeEnd":1054,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L1018-L1054","documentation":"FavoriteStorageError thrown by renameTag when any step of the rename (updating the tag library, rewriting favorites' tag arrays, or updateStats) fails with a non-FavoriteError.","triggerScenarios":"Any updateData/put failure during the multi-write rename; favorites containing malformed tag arrays causing the rewrite to throw.","commonSituations":"Quota exceeded while rewriting many favorites; storage provider failures mid-rename; corrupted favorite records.","solutions":["Check the wrapped message to identify which write failed","Verify favorite records' tags fields are arrays of strings","Retry after freeing storage; use updateStats sparingly to avoid extra writes"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;","tryCatchPattern":"try { return await manager.renameTag(oldTag, newTag); } catch (e) { if (isFavoriteStorageError(e)) { /* verify tag library consistency before retry */ } throw e; }","preventionTips":["Ensure favorites' tags fields are string arrays","Batch renames during low-activity periods to avoid write races"],"tags":["storage","tags","rename","favorites"],"backgroundTag":"storage-write-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}