linshenkx/prompt-optimizer · error · FavoriteStorageError

Failed to update category: ${errorMessage}

Error message

Failed to update category: ${errorMessage}

What it means

Generic storage wrapper thrown by updateCategory when the storage operation fails for a reason other than a known FavoriteError. It wraps the original error message (and preserves non-Favorite errors only if they aren't FavoriteError instances).

Source

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

        const categoriesList = categories || [];
        const index = categoriesList.findIndex(c => c.id === id);
        if (index === -1) {
          throw new FavoriteCategoryNotFoundError(id);
        }

        categoriesList[index] = {
          ...categoriesList[index],
          ...updates
        };

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

  /**
   * 删除分类
   * 会自动清空该分类下所有收藏的分类字段
   *
   * @param id 分类ID
   * @returns 受影响的收藏数量
   */
  async deleteCategory(id: string): Promise<number> {
    await this.ensureInitialized();

    try {
      // ✅ 获取该分类下的所有收藏
      const allFavorites = await this.getFavorites();
      const favoritesInCategory = allFavorites.filter(f => f.category === id);

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Read the embedded errorMessage to find the underlying cause
  2. Retry once for transient provider failures
  3. Check storage availability/quota before performing updates
  4. Validate updates payload is serializable (no functions/cycles)
Defensive patterns

Strategy: retry

Type guard

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

Try / catch

try { await manager.updateCategory(id, updates); } catch (e) { if (isFavoriteStorageError(e) && isTransient(e.cause)) { await retry(() => manager.updateCategory(id, updates), 1); } else throw e; }

Prevention

When it happens

Trigger: storageProvider.updateData throws a raw Error (quota, I/O, serialization) while renaming or recategorizing; the update callback mutates data in a way the provider cannot serialize.

Common situations: Storage quota exceeded during updates; custom storage provider bugs; transient IndexedDB/async-storage failures on mobile.

Related errors


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