{"record":{"id":"b21c86f0a02b4276","repo":"linshenkx/prompt-optimizer","slug":"unrecognized-data-structure","errorCode":null,"errorMessage":"Unrecognized data structure","messagePattern":"Unrecognized data structure","errorType":"validation","errorClass":"DataInvalidFormatError","httpStatus":null,"severity":"warning","filePath":"packages/core/src/services/data/manager.ts","lineNumber":124,"sourceCode":"      throw new DataInvalidFormatError('Data must be an object')\n    }\n\n    // Support both old and new format for backward compatibility\n    let dataToImport: Record<string, any>;\n\n    // New format: { version: 1, data: { ... } }\n    if (exportData.version) {\n      if (!exportData.data || typeof exportData.data !== 'object' || Array.isArray(exportData.data)) {\n        throw new DataInvalidFormatError('\"data\" property is missing or not an object')\n      }\n      dataToImport = exportData.data;\n    }\n    // Old format: direct data object { history: [...], models: [...], ... }\n    else if (exportData.history || exportData.models || exportData.imageModels || exportData.userTemplates || exportData.userSettings || exportData.contexts) {\n      dataToImport = exportData;\n    }\n    else {\n      throw new DataInvalidFormatError('Unrecognized data structure')\n    }\n\n    const errors: string[] = [];\n\n    // 使用各服务的importData接口\n    const serviceMap = [\n      { service: this.historyManager, dataKey: 'history' },\n      { service: this.modelManager, dataKey: 'models' },\n      ...(this.imageModelManager ? [{ service: this.imageModelManager, dataKey: 'imageModels' }] : []),\n      { service: this.templateManager, dataKey: 'userTemplates' },\n      { service: this.preferenceService, dataKey: 'userSettings' },\n      { service: this.contextRepo, dataKey: 'contexts' }\n    ];\n\n    for (const { service, dataKey } of serviceMap) {\n      if (dataToImport[dataKey] !== undefined) {\n        try {\n          await service.importData(dataToImport[dataKey]);","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/data/manager.ts#L106-L142","documentation":"OptimizationError thrown by validateMessageOptimizationRequest when the located selected message has empty/whitespace content (or content undefined). The service refuses to optimize a message with nothing to rewrite — the final fail-fast check before template resolution.","triggerScenarios":"Optimizing a message whose content is '' or only whitespace — e.g. an image-only message with no text, a placeholder/system marker message, or content stripped during serialization.","commonSituations":"Multimodal messages where text is optional, messages created as markers/dividers, content field dropped by a DTO mapper, or whitespace-only drafts saved by a buggy editor.","solutions":["Filter selectable messages to those with non-empty trimmed content in the UI.","If optimizing image-only messages is required, populate content with a caption or placeholder text first.","Audit any serialization layer that could drop the content field.","Catch and show 'this message has no text to optimize'."],"exampleFix":"// before\nconst target = messages.find(m => m.id === selectedId)!; // may be empty\nawait promptService.optimizeMessage({ selectedMessageId: selectedId, messages, modelKey });\n\n// after\nconst target = messages.find(m => m.id === selectedId);\nif (!target?.content?.trim()) return; // not optimizable\nawait promptService.optimizeMessage({ selectedMessageId: selectedId, messages, modelKey });","handlingStrategy":"validation","validationCode":"const target = messages.find(m => m.id === selectedId);\nif (!target?.content?.trim()) throw new Error('Message has no text');","typeGuard":"function hasTextContent(m: unknown): boolean {\n  return typeof (m as any)?.content === 'string' && (m as any).content.trim() !== '';\n}","tryCatchPattern":"try { await svc.optimizeMessage(req); } catch (e) { if (e instanceof OptimizationError && /content cannot be empty/.test(e.message)) showMessage('Nothing to optimize'); }","preventionTips":["Only make text-bearing messages selectable for optimization","Guard against image-only/marker messages","Audit DTOs for dropped content fields"],"tags":["validation","message-optimization","empty-content"],"backgroundTag":"required-field-missing","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}