linshenkx/prompt-optimizer · warning · FavoriteValidationError
CATEGORY_ALREADY_EXISTS
CATEGORY_ALREADY_EXISTS
Error message
${error.message} || 'Category already exists' What it means
Legacy error path: main process returned CATEGORY_ALREADY_EXISTS, converted to FavoriteValidationError (legacy mapping, newer code uses a dedicated category-exists error). Thrown when creating a category whose name/identity already exists.
Source
Thrown at packages/core/src/services/favorite/electron-proxy.ts:69
// 将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 || '');
}
if (error.code === 'TAG_ERROR') {
throw new FavoriteTagError(FAVORITE_ERROR_CODES.TAG_ERROR, error.message || '', { details: error.message || '' });
}
// 数据迁移和导入导出错误
if (error.code === 'MIGRATION_ERROR') {
throw new FavoriteMigrationError(error.message || '', error.cause);
}
if (error.code === 'IMPORT_EXPORT_ERROR') {
throw new FavoriteImportExportError(error.message || '', error.cause, error.details);
}View on GitHub (pinned to 3e677b1d9f)
Solutions
- Check existing category names before creating (case-insensitively if appropriate)
- Disable the submit button while the request is pending
- Catch FavoriteValidationError for category creation and check for 'already exists' messaging
- Upgrade main+renderer together so the non-legacy error code is used
Example fix
// before await mgr.createCategory(name); // after const exists = (await mgr.getCategories()).some(c => c.name === name); if (!exists) await mgr.createCategory(name);
Defensive patterns
Strategy: validation
Validate before calling
const names = new Set((await mgr.getCategories()).map(c => c.name.toLowerCase())); if (!names.has(name.toLowerCase())) await mgr.createCategory(name);
Type guard
const isLegacyCategoryExists = (e: unknown) => e instanceof FavoriteValidationError && /already exists/i.test(e.message);
Try / catch
try { await mgr.createCategory(name); } catch (e) { if (isLegacyCategoryExists(e)) return; throw e; } Prevention
- Check for existing names case-insensitively before create
- Debounce duplicate submissions
- Upgrade main+renderer together to retire the legacy code
When it happens
Trigger: createCategory with a name that already exists, via the Electron proxy talking to an older main-process version.
Common situations: Double-submit of the create-category form; version skew between proxy and main (older main still emits CATEGORY_ALREADY_EXISTS); user retyping an existing category name.
Related errors
- FAVORITE_ALREADY_EXISTS
- CATEGORY_NOT_FOUND
- TAG_ALREADY_EXISTS
- Category already exists: ${category.name}
- FAVORITE_NOT_FOUND
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/ffeda7110894ca41.
Report an issue: GitHub.