linshenkx/prompt-optimizer · error · FavoriteValidationError
Invalid function mode in import data: functionMode=${functio
Error message
Invalid function mode in import data: functionMode=${functionMode}, optimizationMode=${optimizationMode}, imageSubMode=${imageSubMode} What it means
Each imported favorite's mode combination must pass TypeMapper.validateMapping for { functionMode, optimizationMode, imageSubMode }. Defaults are applied first (functionMode 'basic', optimizationMode 'system' for non-image modes, imageSubMode 'text2image' for image), so this only fires when explicit values are invalid or inconsistent.
Source
Thrown at packages/core/src/services/favorite/manager.ts:1355
const favoritesToImport = Array.isArray(importData.favorites) ? importData.favorites : [];
favoritesToImport.forEach((favorite: any) => {
try {
if (!favorite || typeof favorite.content !== 'string' || !favorite.content.trim()) {
throw new FavoriteValidationError('Import data contains favorite with empty content');
}
const functionMode = favorite.functionMode || 'basic';
const optimizationMode =
favorite.optimizationMode ||
(functionMode !== 'image' ? 'system' : undefined);
const imageSubMode =
favorite.imageSubMode ||
(functionMode === 'image' ? 'text2image' : undefined);
const mapping = { functionMode, optimizationMode, imageSubMode };
if (!TypeMapper.validateMapping(mapping)) {
throw new FavoriteValidationError(
`Invalid function mode in import data: functionMode=${functionMode}, optimizationMode=${optimizationMode}, imageSubMode=${imageSubMode}`
);
}
const category = categoryMapping[favorite.category] || favorite.category;
const tags = sanitizeTags(favorite.tags);
const createdAt = parseTimestamp(favorite.createdAt, baseTimestamp + timestampOffset);
const updatedAt = parseTimestamp(favorite.updatedAt, createdAt);
const useCount = typeof favorite.useCount === 'number' && favorite.useCount >= 0
? favorite.useCount
: 0;
const existingFavorite = existingFavoritesMap.get(favorite.content);
if (existingFavorite) {
if (mergeStrategy === 'skip') {
result.skipped++;
return;View on GitHub (pinned to 3e677b1d9f)
Solutions
- Check the library's supported functionMode/optimizationMode/imageSubMode values and fix the offending entries (the error message names the exact invalid triple)
- Upgrade or pin the library to the version whose TypeMapper knows the modes in your export
- Normalize legacy mode names to current ones before importing
Example fix
// before
const fav = { content: 'x', functionMode: 'img', optimizationMode: 'system' };
// after
const fav = { content: 'x', functionMode: 'image', imageSubMode: 'text2image' }; Defensive patterns
Strategy: validation
Validate before calling
import { TypeMapper } from '<lib>';
const ok = parsed.favorites.every((f: any) =>
TypeMapper.validateMapping({
functionMode: f.functionMode || 'basic',
optimizationMode: f.optimizationMode || (f.functionMode !== 'image' ? 'system' : undefined),
imageSubMode: f.imageSubMode || (f.functionMode === 'image' ? 'text2image' : undefined),
})
); Type guard
const isValidModes = (f: any): boolean =>
TypeMapper.validateMapping({
functionMode: f.functionMode || 'basic',
optimizationMode: f.optimizationMode || (f.functionMode !== 'image' ? 'system' : undefined),
imageSubMode: f.imageSubMode || (f.functionMode === 'image' ? 'text2image' : undefined),
}); Try / catch
try {
await manager.importFavorites(data);
} catch (e) {
if (e instanceof FavoriteValidationError && /Invalid function mode/.test(e.message)) {
// message names the invalid triple; normalize or drop the offending entries and retry
}
} Prevention
- Pin import/export to the same library version
- Normalize legacy mode names to the current enums before importing
- Test imports with a small representative file after upgrading the library
When it happens
Trigger: Importing a favorite with an unknown functionMode, an invalid optimizationMode, or an image-mode entry whose imageSubMode/optimizationMode combination is not a registered mapping.
Common situations: Exports produced by a newer or older library version with renamed/added modes, manually edited mode strings, or data from a different product line with its own mode vocabulary.
Related errors
- Invalid import data format
- Import data contains favorite with empty content
- CONTEXT_ERROR_CODES.STORAGE_ERROR
- CONTEXT_ERROR_CODES.IMPORT_FORMAT_ERROR
- DATA_ERROR_CODES.ELECTRON_API_UNAVAILABLE
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/7ea4759531d2b704.
Report an issue: GitHub.