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

  1. Inspect the wrapped message; if it mentions tag conversion, audit stored tag entries for malformed fields
  2. Rebuild the tag library from favorites if corrupted
  3. 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

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


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/c643302c14c31fc3. Report an issue: GitHub.