linshenkx/prompt-optimizer · error · FavoriteStorageError

Failed to delete tag

Error message

Failed to delete tag: ${errorMessage}

What it means

FavoriteStorageError thrown by deleteTag when any of the deletion writes (tag library removal, rewriting favorites to drop the tag) or updateStats fails with a non-FavoriteError.

Solutions

  1. Check the wrapped cause message
  2. Verify favorites' tags arrays after failure and repair inconsistencies
  3. Retry once storage space is available
Defensive patterns

Strategy: try-catch

Type guard

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

Try / catch

try { return await manager.deleteTag(tag); } catch (e) { if (isFavoriteStorageError(e)) { /* verify favorites no longer reference the tag inconsistently; repair */ } throw e; }

Prevention

When it happens

Trigger: Storage write failures while rewriting favorites that referenced the deleted tag; quota exhaustion on large datasets.

Common situations: Deleting a heavily-used tag requiring many favorite rewrites; provider I/O errors; partial deletion leaving inconsistencies.

Related errors


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

Appendix: source

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

        const favoritesList = favorites || [];

        favoritesList.forEach(favorite => {
          const index = favorite.tags.indexOf(tag);
          if (index !== -1) {
            favorite.tags.splice(index, 1);
            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[] = [];

View on GitHub (pinned to 3e677b1d9f)