linshenkx/prompt-optimizer · error · FavoriteStorageError
Failed to reorder categories: ${errorMessage}
Error message
Failed to reorder categories: ${errorMessage} What it means
FavoriteStorageError thrown by reorderCategories when the storage update that rewrites the category list in the new order fails, or when the reorder callback throws (e.g., an id in the list doesn't match any category and the callback assumes existence).
Source
Thrown at packages/core/src/services/favorite/manager.ts:1184
sortOrder: index
});
categoryMap.delete(id);
}
});
// 将未在ID列表中的分类追加到末尾
categoryMap.forEach(category => {
reorderedCategories.push({
...category,
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;View on GitHub (pinned to 3e677b1d9f)
Solutions
- Refresh getCategories() and build the id list from current data before reordering
- Check the wrapped message; if reorder logic threw, verify every id exists
- Retry after resolving storage issues
Example fix
// before await manager.reorderCategories(lastKnownOrder); // after const current = await manager.getCategories(); const validIds = lastKnownOrder.filter(id => current.some(c => c.id === id)); if (validIds.length) await manager.reorderCategories(validIds);
Defensive patterns
Strategy: validation
Validate before calling
const current = await manager.getCategories(); const validIds = categoryIds.filter(id => current.some(c => c.id === id)); if (validIds.length) await manager.reorderCategories(validIds);
Type guard
const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;
Try / catch
try { await manager.reorderCategories(ids); } catch (e) { if (isFavoriteStorageError(e)) { /* refresh categories, rebuild id list, retry once */ } throw e; } Prevention
- Build reorder id lists from fresh getCategories() data
- Re-validate ids after any concurrent deletion
When it happens
Trigger: updateData failing on write; passing ids that don't correspond to stored categories causing the reorder logic inside the callback to throw a non-FavoriteError.
Common situations: Reordering with stale ids after concurrent deletion; storage quota/I-O failures; multi-tab edits producing divergent id lists.
Related errors
- Category ID list cannot be empty
- Failed to get category usage: ${errorMessage}
- Failed to delete favorite prompt asset version: ${errorMessa
- Category already exists: ${category.name}
- Failed to add category: ${errorMessage}
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/90634ea00838a9aa.
Report an issue: GitHub.