{"record":{"id":"e6afc67d918b5e26","repo":"linshenkx/prompt-optimizer","slug":"image-mode-must-specify-imagesubmode","errorCode":null,"errorMessage":"Image mode must specify imageSubMode","messagePattern":"Image mode must specify imageSubMode","errorType":"validation","errorClass":"FavoriteValidationError","httpStatus":null,"severity":"warning","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":283,"sourceCode":"    if (!favorite.content?.trim()) {\n      throw new FavoriteValidationError('Prompt content cannot be empty');\n    }\n\n    // 验证 functionMode 必填\n    if (!favorite.functionMode) {\n      throw new FavoriteValidationError('Function mode (functionMode) cannot be empty');\n    }\n\n    // 验证功能模式分类的完整性\n    if (favorite.functionMode === 'basic' || favorite.functionMode === 'context') {\n      if (!favorite.optimizationMode) {\n        throw new FavoriteValidationError(`${favorite.functionMode} mode must specify optimizationMode`);\n      }\n    }\n\n    if (favorite.functionMode === 'image') {\n      if (!favorite.imageSubMode) {\n        throw new FavoriteValidationError('Image mode must specify imageSubMode');\n      }\n    }\n\n    assertFavoriteMetadataHasNoInlineImages(favorite.metadata);\n\n    const favoriteData = {\n      title: favorite.title?.trim() || favorite.content.slice(0, 50) + (favorite.content.length > 50 ? '...' : ''),\n      content: favorite.content,\n      description: favorite.description,\n      category: favorite.category,\n      tags: favorite.tags || [],\n      functionMode: favorite.functionMode,\n      optimizationMode: favorite.optimizationMode,\n      imageSubMode: favorite.imageSubMode,\n      metadata: favorite.metadata\n    };\n\n    const now = Date.now();","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L265-L301","documentation":"addFavorite requires image-mode favorites to declare imageSubMode; without it the image function mode is ambiguous and FavoriteValidationError is thrown.","triggerScenarios":"addFavorite({ functionMode: 'image' }) with no imageSubMode.","commonSituations":"Image-mode favorites added by code paths that predate imageSubMode; forms missing the sub-mode selector; imports of old favorites without the field.","solutions":["Set imageSubMode whenever functionMode is 'image'","Validate in the form: image mode reveals a mandatory sub-mode picker","Map old imported favorites to a default imageSubMode before insert"],"exampleFix":"// before\nawait manager.addFavorite({ content, functionMode: 'image' });\n// after\nawait manager.addFavorite({ content, functionMode: 'image', imageSubMode: 'generation' });","handlingStrategy":"validation","validationCode":"if (fav.functionMode === 'image' && !fav.imageSubMode) fav.imageSubMode = 'generation';","typeGuard":"const isImageModeComplete = (f: Partial<FavoritePrompt>): f is FavoritePrompt & { imageSubMode: string } =>\n  f.functionMode !== 'image' || !!f.imageSubMode;","tryCatchPattern":"try { await manager.addFavorite(fav); } catch (e) { if (e instanceof FavoriteValidationError && /imageSubMode/.test(e.message)) { pickSubMode(); return; } throw e; }","preventionTips":["Show a mandatory sub-mode picker when image mode is selected","Default old imports to a stable imageSubMode","Test the image-mode happy path"],"tags":["favorite","validation","image","mode-config"],"backgroundTag":"required-field-missing","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}