linshenkx/prompt-optimizer · error · FavoriteStorageError

Failed to merge tags: ${errorMessage}

Error message

Failed to merge tags: ${errorMessage}

What it means

FavoriteStorageError thrown by mergeTags when any of its multiple storage writes (removing source tags from the tag library, adding the target, rewriting favorites' tags) or the final updateStats fails.

Source

Thrown at packages/core/src/services/favorite/manager.ts:1104

          // 如果存在源标签,添加目标标签(如果不存在)
          if (hasSourceTag) {
            if (!favorite.tags.includes(targetTag)) {
              favorite.tags.push(targetTag);
            }
            favorite.updatedAt = Date.now();
            affectedCount++;
          }
        });

        return favoritesList;
      });

      await this.updateStats();
      return affectedCount;
    } catch (error) {
      const errorMessage = error instanceof Error ? error.message : String(error);
      throw new FavoriteStorageError(`Failed to merge tags: ${errorMessage}`);
    }
  }

  async deleteTag(tag: string): Promise<number> {
    if (!tag) {
      throw new FavoriteValidationError('Tag name cannot be empty');
    }

    let affectedCount = 0;

    try {
      // 1. 从独立标签中删除
      await this.storageProvider.updateData(this.STORAGE_KEYS.TAGS, (tags: FavoriteTag[] | null) => {
        const tagsList = tags || [];
        return tagsList.filter(t => t.tag !== tag);
      });

      // 2. 从所有收藏项中删除

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Inspect the wrapped message for the failing step
  2. Verify data consistency after a failed merge (tag library vs favorites) and repair
  3. Free storage or merge fewer tags at a time
Defensive patterns

Strategy: try-catch

Type guard

const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;

Try / catch

try { return await manager.mergeTags(sources, target); } catch (e) { if (isFavoriteStorageError(e)) { /* audit tag library + favorites for partial merge, repair, optionally retry */ } throw e; }

Prevention

When it happens

Trigger: Quota/I/O failure during the multi-step merge; malformed tag data causing the rewrite callbacks to throw.

Common situations: Merging large numbers of tags exceeding quota; interrupted writes leaving partially merged state; corrupted favorite tag arrays.

Related errors


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