{"record":{"id":"b2b675dc5568c4b5","repo":"vercel/ai","slug":"unsupported-role-exhaustivecheck","errorCode":null,"errorMessage":"Unsupported role: ${_exhaustiveCheck}","messagePattern":"Unsupported role: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/alibaba/src/convert-to-alibaba-chat-messages.ts","lineNumber":216,"sourceCode":"            role: 'tool',\n            tool_call_id: toolResponse.toolCallId,\n            content: partCacheControl\n              ? [\n                  {\n                    type: 'text',\n                    text: contentValue,\n                    cache_control: partCacheControl,\n                  },\n                ]\n              : contentValue,\n          });\n        }\n        break;\n      }\n\n      default: {\n        const _exhaustiveCheck: never = role;\n        throw new Error(`Unsupported role: ${_exhaustiveCheck}`);\n      }\n    }\n  }\n\n  return messages;\n}\n","sourceCodeStart":198,"sourceCodeEnd":223,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/alibaba/src/convert-to-alibaba-chat-messages.ts#L198-L223","documentation":"convertToAlibabaChatMessages switches over each prompt message role ('system', 'user', 'assistant', 'tool'); the default branch is an exhaustiveness check that should be unreachable. Hitting it means a message with a role the Alibaba converter does not recognize reached the conversion step, and the TypeScript never-narrowing failed at runtime (e.g. due to a cast or an untyped object).","triggerScenarios":"Calling generateText/streamText with an alibaba chat model and passing a message whose role is not one of the four supported strings — typically via an `as any`/untyped prompt array, or a plugin/interceptor injecting a custom message object.","commonSituations":"Constructing prompt arrays programmatically from an API payload with a typo like 'usr' or 'system_message'; older/newer SDK message types leaking into the prompt; JSON-driven message construction without schema validation.","solutions":["Inspect the prompt array you pass to generateText/streamText and fix or remove the message with the invalid role","Validate message roles against 'system' | 'user' | 'assistant' | 'tool' before building the prompt","Remove any `as any`/type assertions that bypass Message typing","Update the ai package and @ai-sdk/alibaba to latest versions in case a new core message role was added without provider support"],"exampleFix":"// before\nconst messages = [{ role: 'system_message', content: 'hi' } as any];\nawait generateText({ model: alibaba('qwen-max'), messages });\n// after\nconst messages: Array<CoreMessage> = [{ role: 'system', content: 'hi' }];\nawait generateText({ model: alibaba('qwen-max'), messages });","handlingStrategy":"validation","validationCode":"const VALID = new Set(['system','user','assistant','tool']);\nfunction assertValidRoles(messages: unknown[]): asserts messages {\n  for (const m of messages as { role: string }[]) {\n    if (!VALID.has(m.role)) throw new Error(`Invalid message role: ${m.role}`);\n  }\n}\nassertValidRoles(messages);","typeGuard":"function isCoreMessage(m: unknown): m is CoreMessage {\n  return typeof m === 'object' && m !== null &&\n    ['system','user','assistant','tool'].includes((m as any).role);\n}","tryCatchPattern":null,"preventionTips":["Type prompt arrays as CoreMessage[] and avoid `as any`","Validate externally sourced messages with zod before building the prompt"],"tags":["provider","typescript","exhaustive-switch","message-conversion"],"backgroundTag":"unsupported-message-role","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}