linshenkx/prompt-optimizer · warning · FavoriteValidationError
Tag name cannot be empty
Error message
Tag name cannot be empty
What it means
FavoriteValidationError thrown by addTag when the tag string is empty after trimming. Tags must be non-blank strings.
Source
Thrown at packages/core/src/services/favorite/manager.ts:927
.map(([tag, count]) => ({ tag, count }))
.sort((a, b) => {
if (b.count !== a.count) {
return b.count - a.count; // 按使用次数降序
}
return TagTypeConverter.compareTagNames(a.tag, b.tag); // 相同次数按标签名升序
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new FavoriteStorageError(`Failed to get tags: ${errorMessage}`);
}
}
async addTag(tag: string): Promise<void> {
await this.ensureInitialized();
const trimmedTag = tag.trim();
if (!trimmedTag) {
throw new FavoriteValidationError('Tag name cannot be empty');
}
let added = false;
try {
await this.storageProvider.updateData(this.STORAGE_KEYS.TAGS, (tags: FavoriteTag[] | null) => {
const tagsList = tags || [];
// 检查是否已存在
const existing = tagsList.find(t => t.tag === trimmedTag);
if (existing) {
// 标签已存在,保持幂等,不再抛错
return tagsList;
}
const now = Date.now();
const newTag: FavoriteTag = {
tag: trimmedTag,View on GitHub (pinned to 3e677b1d9f)
Solutions
- Trim and validate input before calling addTag
- Disable tag-adding UI actions when input is blank
Example fix
// before await manager.addTag(rawInput); // after const t = rawInput?.trim(); if (t) await manager.addTag(t);
Defensive patterns
Strategy: validation
Validate before calling
const t = tag?.trim(); if (t) await manager.addTag(t);
Prevention
- Trim and check tag inputs at the UI boundary
- Disable add-tag action for blank inputs
When it happens
Trigger: Calling addTag(''), addTag(' '), or addTag of a whitespace-only string.
Common situations: UI allowing empty tag input; programmatic tag creation from unvalidated user input; passing undefined coerced to string.
Related errors
- Source tag list cannot be empty
- Target tag cannot be empty
- Prompt content cannot be empty
- Cannot delete the last prompt asset version
- Cannot delete the current prompt asset version
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/dde85c0ba77a51a5.
Report an issue: GitHub.