linshenkx/prompt-optimizer · error · FavoriteStorageError
Failed to get category usage: ${errorMessage}
Error message
Failed to get category usage: ${errorMessage} What it means
Thrown by FavoriteManager.getCategoryUsage when this.getFavorites({ categoryId }) throws. The original error's message is captured into a FavoriteStorageError with the 'Failed to get category usage' prefix; this is a persistence-layer failure wrapper, not an input validation error.
Source
Thrown at packages/core/src/services/favorite/manager.ts:1194
sortOrder: reorderedCategories.length
});
});
return reorderedCategories;
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new FavoriteStorageError(`Failed to reorder categories: ${errorMessage}`);
}
}
async getCategoryUsage(categoryId: string): Promise<number> {
try {
const favorites = await this.getFavorites({ categoryId });
return favorites.length;
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new FavoriteStorageError(`Failed to get category usage: ${errorMessage}`);
}
}
async importFavorites(data: string, options?: {
mergeStrategy?: 'skip' | 'overwrite' | 'merge';
categoryMapping?: Record<string, string>;
}): Promise<{
imported: number;
skipped: number;
errors: string[];
}> {
const mergeStrategy = options?.mergeStrategy || 'skip';
const categoryMapping = options?.categoryMapping || {};
const result = { imported: 0, skipped: 0, errors: [] as string[] };
try {
await this.ensureInitialized();
const importData = JSON.parse(data);View on GitHub (pinned to 3e677b1d9f)
Solutions
- Inspect the wrapped message (and the original error) to identify the underlying storage failure — it is appended after the colon
- Ensure FavoriteManager is fully initialized (ensureInitialized) before calling getCategoryUsage
- Check browser storage availability and quota (e.g. navigator.storage.estimate()) if quota issues are suspected
- If storage is corrupted, export what is recoverable, reset the favorites store, and re-import
Example fix
// before
const usage = await manager.getCategoryUsage(catId);
// after
try {
const usage = await manager.getCategoryUsage(catId);
} catch (e) {
if (e instanceof FavoriteStorageError) {
console.error('storage failure:', e.message);
}
} Defensive patterns
Strategy: try-catch
Validate before calling
await manager.ensureInitialized(); // make sure storage is ready before usage queries
Type guard
const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof Error && e.name === 'FavoriteStorageError';
Try / catch
try {
const usage = await manager.getCategoryUsage(categoryId);
} catch (e) {
if (isFavoriteStorageError(e)) {
// message suffix carries the underlying storage error; degrade gracefully
return 0;
}
throw e;
} Prevention
- Initialize the FavoriteManager before querying category usage
- Feature-detect browser storage availability at startup
- Log the wrapped message to diagnose the real storage failure
When it happens
Trigger: Calling getCategoryUsage(categoryId) before ensureInitialized has completed, when the underlying storage backend throws (quota, corruption, permission), or when getFavorites fails for any reason while counting favorites in a category.
Common situations: Browser storage disabled or quota exceeded, storage corrupted after a schema/version change, calling the manager concurrently during initialization, or running in SSR/headless environments without persistent storage.
Related errors
- Failed to delete favorite prompt asset version: ${errorMessa
- Failed to add category: ${errorMessage}
- Failed to reorder categories: ${errorMessage}
- Failed to add favorite: ${errorMessage}
- Failed to get favorites: ${errorMessage}
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/ce000bfbfbbecb33.
Report an issue: GitHub.