{"record":{"id":"7ea4759531d2b704","repo":"linshenkx/prompt-optimizer","slug":"invalid-function-mode-in-import-data-functionmode","errorCode":null,"errorMessage":"Invalid function mode in import data: functionMode=${functionMode}, optimizationMode=${optimizationMode}, imageSubMode=${imageSubMode}","messagePattern":"Invalid function mode in import data: functionMode=(.+?), optimizationMode=(.+?), imageSubMode=(.+?)","errorType":"validation","errorClass":"FavoriteValidationError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":1355,"sourceCode":"        const favoritesToImport = Array.isArray(importData.favorites) ? importData.favorites : [];\n\n        favoritesToImport.forEach((favorite: any) => {\n          try {\n            if (!favorite || typeof favorite.content !== 'string' || !favorite.content.trim()) {\n              throw new FavoriteValidationError('Import data contains favorite with empty content');\n            }\n\n            const functionMode = favorite.functionMode || 'basic';\n            const optimizationMode =\n              favorite.optimizationMode ||\n              (functionMode !== 'image' ? 'system' : undefined);\n            const imageSubMode =\n              favorite.imageSubMode ||\n              (functionMode === 'image' ? 'text2image' : undefined);\n\n            const mapping = { functionMode, optimizationMode, imageSubMode };\n            if (!TypeMapper.validateMapping(mapping)) {\n              throw new FavoriteValidationError(\n                `Invalid function mode in import data: functionMode=${functionMode}, optimizationMode=${optimizationMode}, imageSubMode=${imageSubMode}`\n              );\n            }\n\n            const category = categoryMapping[favorite.category] || favorite.category;\n            const tags = sanitizeTags(favorite.tags);\n            const createdAt = parseTimestamp(favorite.createdAt, baseTimestamp + timestampOffset);\n            const updatedAt = parseTimestamp(favorite.updatedAt, createdAt);\n            const useCount = typeof favorite.useCount === 'number' && favorite.useCount >= 0\n              ? favorite.useCount\n              : 0;\n\n            const existingFavorite = existingFavoritesMap.get(favorite.content);\n\n            if (existingFavorite) {\n              if (mergeStrategy === 'skip') {\n                result.skipped++;\n                return;","sourceCodeStart":1337,"sourceCodeEnd":1373,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L1337-L1373","documentation":"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.","triggerScenarios":"Importing a favorite with an unknown functionMode, an invalid optimizationMode, or an image-mode entry whose imageSubMode/optimizationMode combination is not a registered mapping.","commonSituations":"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.","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"],"exampleFix":"// before\nconst fav = { content: 'x', functionMode: 'img', optimizationMode: 'system' };\n\n// after\nconst fav = { content: 'x', functionMode: 'image', imageSubMode: 'text2image' };","handlingStrategy":"validation","validationCode":"import { TypeMapper } from '<lib>';\nconst ok = parsed.favorites.every((f: any) =>\n  TypeMapper.validateMapping({\n    functionMode: f.functionMode || 'basic',\n    optimizationMode: f.optimizationMode || (f.functionMode !== 'image' ? 'system' : undefined),\n    imageSubMode: f.imageSubMode || (f.functionMode === 'image' ? 'text2image' : undefined),\n  })\n);","typeGuard":"const isValidModes = (f: any): boolean =>\n  TypeMapper.validateMapping({\n    functionMode: f.functionMode || 'basic',\n    optimizationMode: f.optimizationMode || (f.functionMode !== 'image' ? 'system' : undefined),\n    imageSubMode: f.imageSubMode || (f.functionMode === 'image' ? 'text2image' : undefined),\n  });","tryCatchPattern":"try {\n  await manager.importFavorites(data);\n} catch (e) {\n  if (e instanceof FavoriteValidationError && /Invalid function mode/.test(e.message)) {\n    // message names the invalid triple; normalize or drop the offending entries and retry\n  }\n}","preventionTips":["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"],"tags":["import","validation","function-mode","type-mapping","enum"],"backgroundTag":"enum-value-validation-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}