linshenkx/prompt-optimizer · warning · FavoriteValidationError

Source tag list cannot be empty

Error message

Source tag list cannot be empty

What it means

FavoriteValidationError thrown by mergeTags when sourceTags is null, undefined, or an empty array. At least one source tag is required to merge.

Source

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

              createdAt: Date.now()
            });
          }

          return tagsList;
        });
      }

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

  async mergeTags(sourceTags: string[], targetTag: string): Promise<number> {
    if (!sourceTags || sourceTags.length === 0) {
      throw new FavoriteValidationError('Source tag list cannot be empty');
    }

    if (!targetTag) {
      throw new FavoriteValidationError('Target tag cannot be empty');
    }

    let affectedCount = 0;

    try {
      // 1. 更新独立标签库:删除所有源标签,确保目标标签存在
      await this.storageProvider.updateData(this.STORAGE_KEYS.TAGS, (tags: FavoriteTag[] | null) => {
        const tagsList = tags || [];

        // 删除所有源标签
        const filteredTags = tagsList.filter(t => !sourceTags.includes(t.tag));

        // 确保目标标签存在
        const hasTargetTag = filteredTags.some(t => t.tag === targetTag);

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Require at least one selected source tag before enabling merge
  2. Early-return when the selection is empty

Example fix

// before
await manager.mergeTags(selected, target);

// after
if (selected.length > 0 && target) {
  await manager.mergeTags(selected, target);
}
Defensive patterns

Strategy: validation

Validate before calling

if (sourceTags?.length) await manager.mergeTags(sourceTags, targetTag);

Prevention

When it happens

Trigger: Calling mergeTags([], 'target') or mergeTags(null, 'target').

Common situations: UI allowing merge with no source tags selected; programmatic merge built from an empty selection.

Related errors


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