{"record":{"id":"5032e478c817cdfa","repo":"mastra-ai/mastra","slug":"unhandled-content-part-type-exhaustivecheck-as","errorCode":null,"errorMessage":"Unhandled content part type: ${(exhaustiveCheck as { type: string }).type}","messagePattern":"Unhandled content part type: (.+?)\\)\\.type\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client-sdks/react/src/lib/mastra-db/fromCoreUserMessage.ts","lineNumber":42,"sourceCode":"          case 'image': {\n            const mimeType = part.mimeType ?? 'image/*';\n            return {\n              type: 'file' as const,\n              mimeType,\n              data: encodeFilePartDataForStorage(part.image, mimeType),\n            };\n          }\n          case 'file': {\n            return {\n              type: 'file' as const,\n              mimeType: part.mimeType,\n              data: encodeFilePartDataForStorage(part.data, part.mimeType),\n              ...(part.filename !== undefined ? { filename: part.filename } : {}),\n            };\n          }\n          default: {\n            const exhaustiveCheck: never = part;\n            throw new Error(`Unhandled content part type: ${(exhaustiveCheck as { type: string }).type}`);\n          }\n        }\n      });\n\nconst newUserMessage = (parts: MastraMessagePart[]): MastraDBMessage => ({\n  id: `user-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`,\n  role: 'user',\n  createdAt: new Date(),\n  content: {\n    format: 2,\n    parts,\n  },\n});\n\nexport const fromCoreUserMessageToMastraDBMessage = (coreUserMessage: CoreUserMessage): MastraDBMessage =>\n  newUserMessage(coreUserMessageToParts(coreUserMessage));\n\n/**","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/client-sdks/react/src/lib/mastra-db/fromCoreUserMessage.ts#L24-L60","documentation":"This error is thrown by coreUserMessageToParts while converting an AI SDK CoreUserMessage into a MastraDBMessage. The switch over message part types has a `default` branch with a compile-time exhaustive `never` check, so reaching it at runtime means a content part whose `type` was added in a newer AI SDK version (or is otherwise unknown) was passed in. The library throws rather than silently dropping data.","triggerScenarios":"Calling fromCoreUserMessageToMastraDBMessage (via coreUserMessageToParts) with a user message containing a part type not covered by the switch — e.g. a newly introduced AI SDK part kind like a novel file/tool/audio variant that the converter has no case for.","commonSituations":"Mixing AI SDK major versions (message produced by a newer ai package, converted by an older @mastra/client-js/react); manually constructing CoreUserMessage parts with an unexpected `type` string; forwarding model/provider-specific parts straight through.","solutions":["Upgrade @mastra/client-js / @mastra/core (and the react SDK) to a version whose converter covers your AI SDK's part types","Align the `ai` package version with the version the Mastra packages were built against","Intercept and strip/convert unknown parts from the message before calling the converter","Extend/wrap the converter to handle the new part type, or file an issue so the part type gets a case"],"exampleFix":"// before\nconst parts = message.content; // contains { type: 'reasoning', ... } unknown to converter\nfromCoreUserMessageToMastraDBMessage(message); // throws\n// after\nconst supported = message.content.filter(p => ['text','image','file'].includes(p.type));\nfromCoreUserMessageToMastraDBMessage({ ...message, content: supported });","handlingStrategy":"type-guard","validationCode":"const KNOWN_PART_TYPES = ['text','image','file'];\nif (!message.content.every(p => KNOWN_PART_TYPES.includes(p.type))) {\n  throw new Error('Message contains part types unsupported by this Mastra SDK version');\n}","typeGuard":"function isSupportedPart(part: { type: string }): part is TextPart | ImagePart | FilePart {\n  return ['text','image','file'].includes(part.type);\n}","tryCatchPattern":"try {\n  const dbMessage = fromCoreUserMessageToMastraDBMessage(message);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Unhandled content part type')) {\n    console.warn('Skipping unsupported part types; upgrade SDK to support them');\n    // fallback: filter unknown parts and retry\n  } else throw err;\n}","preventionTips":["Pin the `ai` SDK version to one compatible with your @mastra/* packages","Filter or normalize message content before converting","Run a conversion smoke test in CI whenever you bump the AI SDK","Check Mastra release notes for newly supported part types before upgrading ai"],"tags":["typescript","message-conversion","ai-sdk"],"backgroundTag":"unhandled-content-part-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}