{"record":{"id":"aaf6db0cd861f00f","repo":"hcengineering/platform","slug":"unsupported-data-type","errorCode":null,"errorMessage":"Unsupported data type","messagePattern":"Unsupported data type","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"foundations/core/packages/api-client/src/storage/client.ts","lineNumber":178,"sourceCode":"      method: 'DELETE',\n      headers: { ...this.headers }\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 wrappedFetch (url: string | URL, init?: RequestInit): Promise<Response> {\n  let response: Response\n  try {\n    response = await fetch(url, init)\n  } catch (error: any) {\n    throw new NetworkError(`Network error ${error}`)\n  }\n  if (!response.ok) {\n    const text = await response.text()\n    if (response.status === 404) {\n      throw new NotFoundError(text)\n    } else {\n      throw new StorageError(text)\n    }\n  }","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/core/packages/api-client/src/storage/client.ts#L160-L196","documentation":"The private-to-module toBuffer helper accepts only Buffer, string, or Node Readable streams before upload; any other value (e.g. Uint8Array, Blob, plain object, or a browser ReadableStream) falls into the else branch and a TypeError('Unsupported data type') is thrown. It surfaces from storageClient.put() and buffer().","triggerScenarios":"Calling storageClient.put(name, data, contentType) with data that is not Buffer/string/Readable — typically a Uint8Array, ArrayBuffer, Blob, or a web ReadableStream obtained from fetch response.body in a browser context.","commonSituations":"Passing response.body (a Web ReadableStream) directly to put(); passing a File/Blob from a browser file input; TypeScript types not enforced because the value came from an untyped API boundary; code written for a browser SDK reused in Node.","solutions":["Convert the value before calling put: Buffer.from(await new Response(webStream).arrayBuffer()) for web streams.","Use fs.createReadStream(path) for files, or Buffer.from(uint8array) / Buffer.from(await blob.arrayBuffer()) for typed arrays and Blobs.","Ensure TypeScript compiles with the declared put signature (Readable | Buffer | string) so mismatches are caught at build time."],"exampleFix":"// before\nconst res = await fetch(fileUrl)\nawait storage.put(name, res.body, contentType) // TypeError: Unsupported data type\n// after\nconst res = await fetch(fileUrl)\nconst buf = Buffer.from(await res.arrayBuffer())\nawait storage.put(name, buf, contentType)","handlingStrategy":"validation","validationCode":"import { Readable } from 'stream'\nfunction assertPutInput(data: unknown): asserts data is Buffer | string | Readable {\n  if (!Buffer.isBuffer(data) && typeof data !== 'string' && !(data instanceof Readable)) {\n    throw new TypeError(`put() needs Buffer | string | Readable, got ${data?.constructor?.name}`)\n  }\n}","typeGuard":"function isPutInput(data: unknown): data is Buffer | string | Readable {\n  return Buffer.isBuffer(data) || typeof data === 'string' || data instanceof Readable\n}","tryCatchPattern":"try {\n  await storage.put(name, data, contentType)\n} catch (e) {\n  if (e instanceof TypeError && e.message === 'Unsupported data type') {\n    // convert and retry once\n    const buf = Buffer.from(await new Response(data as any).arrayBuffer())\n    return storage.put(name, buf, contentType)\n  }\n  throw e\n}","preventionTips":["Coerce web streams/Blobs/Uint8Arrays to Buffer before calling put().","Use Readable.from(webStream) (Node 18+) to adapt web streams in Node.","Enable strict TypeScript so put() signature mismatches fail at compile time.","Centralize file-input handling in one helper that always yields Buffer or Readable."],"tags":["storage","typeerror","nodejs","input-validation"],"backgroundTag":"unsupported-argument-type","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}