{"record":{"id":"bec7b5218177bc04","repo":"vercel/ai","slug":"unsupported-chunk-type-exhaustivecheck-bec7b5","errorCode":null,"errorMessage":"Unsupported chunk type: ${_exhaustiveCheck}","messagePattern":"Unsupported chunk type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-object/stream-object.ts","lineNumber":999,"sourceCode":"\n  get partialObjectStream(): AsyncIterableStream<PARTIAL> {\n    return createAsyncIterableStream(\n      this.baseStream.pipeThrough(\n        new TransformStream<ObjectStreamPart<PARTIAL>, PARTIAL>({\n          transform(chunk, controller) {\n            switch (chunk.type) {\n              case 'object':\n                controller.enqueue(chunk.object);\n                break;\n\n              case 'text-delta':\n              case 'finish':\n              case 'error': // suppress error (use onError instead)\n                break;\n\n              default: {\n                const _exhaustiveCheck: never = chunk;\n                throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);\n              }\n            }\n          },\n        }),\n      ),\n    );\n  }\n\n  get elementStream(): ELEMENT_STREAM {\n    return this.outputStrategy.createElementStream(this.baseStream);\n  }\n\n  get textStream(): AsyncIterableStream<string> {\n    return createAsyncIterableStream(\n      this.baseStream.pipeThrough(\n        new TransformStream<ObjectStreamPart<PARTIAL>, string>({\n          transform(chunk, controller) {\n            switch (chunk.type) {","sourceCodeStart":981,"sourceCodeEnd":1017,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-object/stream-object.ts#L981-L1017","documentation":"In stream-object.ts, a TransformStream switches over ObjectStreamPart types and throws this Error from the `default` branch when it encounters a part type it doesn't handle. The switch is exhaustive over the known union, so at runtime this indicates a stream part produced outside the expected type set — typically a package version mismatch or non-standard chunks injected into the stream.","triggerScenarios":"Mixed versions of `ai`/`@ai-sdk/*` in one app (stale lockfile, bundler duplication) so the stream emits a part the consumer doesn't know; custom provider/middleware emitting unknown chunk types; monkey-patched streams.","commonSituations":"After upgrading the AI SDK without reinstalling; monorepos resolving two copies of `ai`; experiments with custom stream transforms feeding streamObject internals.","solutions":["Reinstall dependencies and ensure a single `ai` version (`pnpm why ai`; dedupe).","Rebuild the app after upgrades so stream producers and consumers share types.","Remove custom patches that inject unknown parts; if it persists on a clean install, report a bug with the chunk type from the message."],"exampleFix":"// before\n\"ai\": \"^4.0.0\" with a nested ai@3.4 in pnpm-lock.yaml\n\n// after\nrm -rf node_modules pnpm-lock.yaml && pnpm install\n\"ai\": \"^4.3.16\"","handlingStrategy":"fallback","validationCode":"// detect version skew early\nimport { VERSION } from 'ai';\nif (VERSION !== expectedAiVersion) console.warn('ai version mismatch:', VERSION);","typeGuard":"function isUnsupportedChunkError(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith('Unsupported chunk type');\n}","tryCatchPattern":"try {\n  for await (const part of result.partialObjectStream) { /* ... */ }\n} catch (e) {\n  if (isUnsupportedChunkError(e)) {\n    console.error('SDK stream/type mismatch — reinstall dependencies');\n    // fallback: await result.object for the final value\n  } else throw e;\n}","preventionTips":["Pin one version of `ai` across the workspace.","Clean install and dedupe after every SDK upgrade.","Avoid custom middleware that adds unknown stream parts.","Report persistent occurrences with the chunk type from the message."],"tags":["streaming","exhaustiveness","version-mismatch","internal-error"],"backgroundTag":"unsupported-chunk-type","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}