linshenkx/prompt-optimizer · error · FavoriteCategoryNotFoundError
CATEGORY_NOT_FOUND
CATEGORY_NOT_FOUND
Error message
${error.id} What it means
Main process returned CATEGORY_NOT_FOUND; converted to FavoriteCategoryNotFoundError carrying the category id. The referenced favorite category does not exist in storage.
Source
Thrown at packages/core/src/services/favorite/electron-proxy.ts:59
this.ensureApiAvailable();
try {
const safeArgs = safeSerializeArgs(...args);
return await (window.electronAPI.favoriteManager as any)[method](...safeArgs);
} catch (error: any) {
// New i18n-style structured errors: pass through as-is so UI can translate via `code + params`.
if (typeof error?.code === 'string' && error.code.startsWith('error.')) {
throw toErrorWithCode(error)
}
// 将IPC错误转换为具体的错误类型
if (error.code === 'FAVORITE_NOT_FOUND') {
throw new FavoriteNotFoundError(error.id || '');
}
if (error.code === 'FAVORITE_ALREADY_EXISTS') {
throw new FavoriteAlreadyExistsError(error.content || '');
}
if (error.code === 'CATEGORY_NOT_FOUND') {
throw new FavoriteCategoryNotFoundError(error.id || '');
}
if (error.code === 'VALIDATION_ERROR') {
throw new FavoriteValidationError(error.message || '');
}
if (error.code === 'STORAGE_ERROR') {
throw new FavoriteStorageError(error.message || '');
}
// Legacy: category already exists
if (error.code === 'CATEGORY_ALREADY_EXISTS') {
throw new FavoriteValidationError(error.message || 'Category already exists')
}
// 标签相关错误
if (error.code === 'TAG_ALREADY_EXISTS') {
throw new FavoriteTagAlreadyExistsError(error.tag || '');
}
if (error.code === 'TAG_NOT_FOUND') {
throw new FavoriteTagNotFoundError(error.tag || '');
}View on GitHub (pinned to 3e677b1d9f)
Solutions
- Reload categories and let the user re-pick a valid one
- Catch FavoriteCategoryNotFoundError and reset the form's category selection
- Verify categoryId is set from a fresh fetch, not hardcoded
- Recreate missing categories or map to a fallback category before insert
Example fix
// before
await mgr.addFavorite({ ...fav, categoryId });
// after
const cats = await mgr.getCategories();
if (!cats.some(c => c.id === categoryId)) categoryId = cats[0]?.id;
await mgr.addFavorite({ ...fav, categoryId }); Defensive patterns
Strategy: validation
Validate before calling
const cats = await mgr.getCategories(); if (!cats.some(c => c.id === categoryId)) categoryId = cats[0]?.id;
Type guard
const isCategoryNotFound = (e: unknown): e is FavoriteCategoryNotFoundError => e instanceof FavoriteCategoryNotFoundError;
Try / catch
try { await mgr.addFavorite(payload); } catch (e) { if (isCategoryNotFound(e)) { await refreshCategories(); return retryWithFreshCategory(); } throw e; } Prevention
- Load categories lazily right before submit
- Drop deleted categories from selection state
- Handle 'no categories exist' explicitly
When it happens
Trigger: addFavorite/updateFavorite with a categoryId that was deleted, or category operations on a stale category id, via the Electron proxy.
Common situations: Category deleted in another window while a form was open; stale category list in UI state; default category removed by user; migration dropped old categories.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- FAVORITE_NOT_FOUND
- Tag not found: ${error.tag || ''}
- FAVORITE_ALREADY_EXISTS
- VALIDATION_ERROR
- STORAGE_ERROR
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/49132a1b2f98ccff.
Report an issue: GitHub.