{"record":{"id":"5e7b4b5dc6f66052","repo":"hcengineering/platform","slug":"unsupported-data-type-5e7b4b","errorCode":null,"errorMessage":"Unsupported data type","messagePattern":"Unsupported data type","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"foundations/server/packages/datalake/src/client.ts","lineNumber":495,"sourceCode":"      ctx.error('failed to abort multipart upload', { workspace, objectName, err })\n      throw new DatalakeError('Failed to abort multipart upload')\n    }\n  }\n}\n\nasync function toBuffer (data: Buffer | string | Readable): Promise<Buffer> {\n  if (Buffer.isBuffer(data)) {\n    return data\n  } else if (typeof data === 'string') {\n    return Buffer.from(data)\n  } else if (data instanceof Readable) {\n    const chunks: Buffer[] = []\n    for await (const chunk of data) {\n      chunks.push(chunk)\n    }\n    return Buffer.concat(chunks as any)\n  } else {\n    throw new TypeError('Unsupported data type')\n  }\n}\n\nasync function * getChunks (data: Buffer | string | Readable, chunkSize: number): AsyncGenerator<Buffer> {\n  if (Buffer.isBuffer(data)) {\n    let offset = 0\n    while (offset < data.length) {\n      yield data.subarray(offset, offset + chunkSize)\n      offset += chunkSize\n    }\n  } else if (typeof data === 'string') {\n    const buffer = Buffer.from(data)\n    yield * getChunks(buffer, chunkSize)\n  } else if (data instanceof Readable) {\n    let buffer = Buffer.alloc(0)\n\n    for await (const chunk of data) {\n      buffer = Buffer.concat([buffer, chunk])","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/server/packages/datalake/src/client.ts#L477-L513","documentation":"TypeError thrown by the internal toBuffer helper when the data argument is neither a Buffer, a string, nor a Node Readable stream. The datalake client only accepts these three types for upload bodies; anything else (Uint8Array, Blob, web ReadableStream, plain object, undefined) reaches the else branch.","triggerScenarios":"Passing an unsupported value as the body to a client upload path that calls toBuffer: e.g. a Uint8Array from TextEncoder/crypto, a Blob/File from web APIs, a JSON object, or undefined because the variable was never assigned.","commonSituations":"Code assuming fetch-style BodyInit acceptance (Uint8Array/Blob); TypeScript unions widened with `as any`; using an API that returns a web ReadableStream instead of a Node Readable.","solutions":["Convert typed arrays before calling: Buffer.from(uint8array).","Wrap web streams with Readable.fromWeb(stream) from 'node:stream'.","Enforce the Buffer | string | Readable union in TypeScript and remove `as any` casts.","Log the value's constructor name to confirm what was actually passed."],"exampleFix":"// before\nawait client.put(ctx, ws, name, encoder.encode('hello')) // Uint8Array\n// after\nawait client.put(ctx, ws, name, Buffer.from(encoder.encode('hello')))","handlingStrategy":"validation","validationCode":"function toUploadBody(data: unknown): Buffer {\n  if (Buffer.isBuffer(data)) return data\n  if (typeof data === 'string') return Buffer.from(data)\n  if (data instanceof Uint8Array) return Buffer.from(data)\n  if (data instanceof Readable) return null as never // handle streams separately\n  throw new TypeError(`Expected Buffer|string|Readable, got ${Object.prototype.toString.call(data)}`)\n}","typeGuard":"const isSupportedBody = (d: unknown): d is Buffer | string | Readable =>\n  Buffer.isBuffer(d) || typeof d === 'string' || d instanceof Readable","tryCatchPattern":"try {\n  await client.put(ctx, ws, name, body)\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes('Unsupported data type')) {\n    console.error('Convert the body to Buffer/string/Readable before uploading')\n  }\n  throw err\n}","preventionTips":["Convert Uint8Array/Blob to Buffer before uploading.","Use Readable.fromWeb() for web streams.","Keep strict TypeScript types on upload arguments; avoid `as any`.","Unit-test upload helpers with all three supported body types."],"tags":["typeerror","types","validation"],"backgroundTag":"unsupported-data-type","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}