{"record":{"id":"dde85c0ba77a51a5","repo":"linshenkx/prompt-optimizer","slug":"tag-name-cannot-be-empty","errorCode":null,"errorMessage":"Tag name cannot be empty","messagePattern":"Tag name cannot be empty","errorType":"validation","errorClass":"FavoriteValidationError","httpStatus":null,"severity":"warning","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":927,"sourceCode":"        .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        // 检查是否已存在\n        const existing = tagsList.find(t => t.tag === trimmedTag);\n        if (existing) {\n          // 标签已存在，保持幂等，不再抛错\n          return tagsList;\n        }\n\n        const now = Date.now();\n        const newTag: FavoriteTag = {\n          tag: trimmedTag,","sourceCodeStart":909,"sourceCodeEnd":945,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L909-L945","documentation":"FavoriteValidationError thrown by addTag when the tag string is empty after trimming. Tags must be non-blank strings.","triggerScenarios":"Calling addTag(''), addTag('   '), or addTag of a whitespace-only string.","commonSituations":"UI allowing empty tag input; programmatic tag creation from unvalidated user input; passing undefined coerced to string.","solutions":["Trim and validate input before calling addTag","Disable tag-adding UI actions when input is blank"],"exampleFix":"// before\nawait manager.addTag(rawInput);\n\n// after\nconst t = rawInput?.trim();\nif (t) await manager.addTag(t);","handlingStrategy":"validation","validationCode":"const t = tag?.trim(); if (t) await manager.addTag(t);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim and check tag inputs at the UI boundary","Disable add-tag action for blank inputs"],"tags":["validation","tags","empty-input","favorites"],"backgroundTag":"empty-input-validation","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}