linshenkx/prompt-optimizer · error · FavoriteStorageError
Failed to get tags: ${errorMessage}
Error message
Failed to get tags: ${errorMessage} What it means
FavoriteStorageError thrown by getTags when reading the independent tag library from storage or while sorting/transforming tags fails.
Source
Thrown at packages/core/src/services/favorite/manager.ts:918
return tagCounts;
}
async getAllTags(): Promise<Array<{ tag: string; count: number }>> {
try {
const tagCounts = await this.computeTagCounts();
// 返回排序后的结果(使用次数降序,相同次数按标签名升序)
return Array.from(tagCounts.entries())
.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 || [];
// 检查是否已存在View on GitHub (pinned to 3e677b1d9f)
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
Defensive patterns
Strategy: fallback
Type guard
const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;
Try / catch
try { return await manager.getTags(); } catch (e) { if (isFavoriteStorageError(e)) { return []; /* derive tags from favorites as fallback */ } throw e; } Prevention
- Keep tag entries well-formed (name + count fields)
- Derive tag lists defensively in read-only views
When it happens
Trigger: storageProvider.getItem/updateData for TAGS failing; tag entries with unexpected shapes causing compare/convert functions to throw during sorting.
Common situations: Corrupted tag store after partial imports; custom or legacy tag data missing fields; provider read failures.
Related errors
- Failed to get statistics: ${errorMessage}
- Failed to add tag: ${errorMessage}
- Failed to rename tag: ${errorMessage}
- Failed to merge tags: ${errorMessage}
- Failed to delete tag: ${errorMessage}
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/c643302c14c31fc3.
Report an issue: GitHub.