linshenkx/prompt-optimizer · warning · FavoriteValidationError

Category ID list cannot be empty

Error message

Category ID list cannot be empty

What it means

FavoriteValidationError thrown by reorderCategories when the categoryIds argument is null, undefined, or an empty array. Reordering requires at least one id.

Source

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

            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 delete tag: ${errorMessage}`);
    }
  }

  async reorderCategories(categoryIds: string[]): Promise<void> {
    if (!categoryIds || categoryIds.length === 0) {
      throw new FavoriteValidationError('Category ID list cannot be empty');
    }

    try {
      await this.storageProvider.updateData(this.STORAGE_KEYS.CATEGORIES, (categories: FavoriteCategory[] | null) => {
        const categoriesList = categories || [];

        // 创建ID到分类的映射
        const categoryMap = new Map<string, FavoriteCategory>();
        categoriesList.forEach(cat => categoryMap.set(cat.id, cat));

        // 按提供的ID顺序重新排序,并更新sortOrder
        const reorderedCategories: FavoriteCategory[] = [];
        categoryIds.forEach((id, index) => {
          const category = categoryMap.get(id);
          if (category) {
            reorderedCategories.push({
              ...category,
              sortOrder: index

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Skip the reorder call when the list is empty
  2. Guard persistence of drag-drop order on categories.length > 0

Example fix

// before
await manager.reorderCategories(ids);

// after
if (ids.length > 0) {
  await manager.reorderCategories(ids);
}
Defensive patterns

Strategy: validation

Validate before calling

if (categoryIds?.length) await manager.reorderCategories(categoryIds);

Prevention

When it happens

Trigger: Calling reorderCategories([]) or reorderCategories(null), e.g. persisting drag-and-drop order when no categories exist.

Common situations: Empty category list UI saving order on teardown; programmatic reorder with unfiltered id lists.

Related errors


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