linshenkx/prompt-optimizer · error · FavoriteStorageError

Failed to delete category: ${errorMessage}

Error message

Failed to delete category: ${errorMessage}

What it means

Generic storage wrapper thrown by deleteCategory when any non-FavoriteError failure occurs during the multi-step delete (clearing favorites' category field, then removing the category).

Source

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

      // ✅ 删除分类
      await this.storageProvider.updateData(this.STORAGE_KEYS.CATEGORIES, (categories: FavoriteCategory[] | null) => {
        const categoriesList = categories || [];
        const index = categoriesList.findIndex(c => c.id === id);
        if (index === -1) {
          throw new FavoriteCategoryNotFoundError(id);
        }

        return categoriesList.filter(c => c.id !== id);
      });

      return favoritesInCategory.length;
    } catch (error) {
      if (error instanceof FavoriteError) {
        throw error;
      }
      const errorMessage = error instanceof Error ? error.message : String(error);
      throw new FavoriteStorageError(`Failed to delete category: ${errorMessage}`);
    }
  }

  async getStats(): Promise<FavoriteStats> {
    try {
      const stats = await this.storageProvider.getItem(this.STORAGE_KEYS.STATS);
      if (stats) {
        return JSON.parse(stats);
      }

      // 如果没有缓存的统计数据,计算并缓存
      return await this.updateStats();
    } catch (error) {
      const errorMessage = error instanceof Error ? error.message : String(error);
      throw new FavoriteStorageError(`Failed to get statistics: ${errorMessage}`);
    }
  }

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Check the wrapped message for the failing step
  2. Verify storage state consistency afterwards (favorites vs categories) and repair if partial
  3. Retry the delete after confirming the category still exists
Defensive patterns

Strategy: try-catch

Type guard

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

Try / catch

try { await manager.deleteCategory(id); } catch (e) { if (isFavoriteStorageError(e)) { /* verify favorites/categories consistency, then recover */ } throw e; }

Prevention

When it happens

Trigger: Either updateData call fails (quota, I/O, provider error) during deletion; partial failure can occur after favorites were already unlinked.

Common situations: Storage failures mid-operation; provider timeouts; interrupted mobile app storage calls.

Related errors


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