{"record":{"id":"c24b2eb28233cee3","repo":"denoland/deno","slug":"err-invalid-arg-type-c24b2e","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"buffer\" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received ${actual}","messagePattern":"The \"buffer\" argument must be of type string or an instance of Buffer, TypedArray, or DataView\\. Received (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/dgram.ts","lineNumber":968,"sourceCode":"\n        if (typeof port === \"function\") {\n          callback = port;\n          port = null;\n        }\n      } else {\n        callback = offset;\n      }\n\n      if (port || address) {\n        throw new ERR_SOCKET_DGRAM_IS_CONNECTED();\n      }\n    }\n\n    if (!ArrayIsArray(buffer)) {\n      if (typeof buffer === \"string\") {\n        list = [Buffer.from(buffer)];\n      } else if (!isArrayBufferView(buffer)) {\n        throw new ERR_INVALID_ARG_TYPE(\n          \"buffer\",\n          [\"Buffer\", \"TypedArray\", \"DataView\", \"string\"],\n          buffer,\n        );\n      } else {\n        list = [buffer as MessageType];\n      }\n    } else if (!(list = fixBufferList(buffer))) {\n      throw new ERR_INVALID_ARG_TYPE(\n        \"buffer list arguments\",\n        [\"Buffer\", \"TypedArray\", \"DataView\", \"string\"],\n        buffer,\n      );\n    }\n\n    if (!connected) {\n      port = validatePort(port, \"Port\", false);\n    }","sourceCodeStart":950,"sourceCodeEnd":986,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/dgram.ts#L950-L986","documentation":"dgram.Socket.send validates the payload before dispatch: when the msg argument is not an array, it must be a string or an ArrayBufferView (Buffer, TypedArray, DataView). Anything else — number, plain object, null, Blob — throws this ERR_INVALID_ARG_TYPE immediately.","triggerScenarios":"socket.send(42, port, host); socket.send({ type: 'ping' }, port, host); socket.send(null, cb); socket.send(new Blob(['x']), port) — any non-array, non-string, non-view single payload.","commonSituations":"Sending a JSON object without stringify/Buffer.from; passing a numeric id or computed value instead of its serialized bytes; passing a Blob where Node's dgram expects a Buffer.","solutions":["Serialize the payload: socket.send(Buffer.from(JSON.stringify(obj)), port, host)","Use Buffer.from(String(value)) for scalars, or str2ab/TextEncoder for strings you want as bytes","If you meant to send several chunks, pass an array of Buffers (each element must itself be valid)"],"exampleFix":"// before\nsock.send({ op: 'PING', seq: 7 }, 41234, '192.168.1.10'); // throws\n\n// after\nsock.send(Buffer.from(JSON.stringify({ op: 'PING', seq: 7 })), 41234, '192.168.1.10');","handlingStrategy":"type-guard","validationCode":"function toMessage(v) {\n  if (typeof v === 'string') return Buffer.from(v);\n  if (ArrayBuffer.isView(v)) return v;\n  throw new TypeError(`unsupported dgram payload: ${typeof v}`);\n}\nsock.send(toMessage(payload), port, host);","typeGuard":"function isDgramPayload(v) {\n  return typeof v === 'string' || ArrayBuffer.isView(v);\n}","tryCatchPattern":null,"preventionTips":["Always serialize objects with Buffer.from(JSON.stringify(x)) before send()","Type send wrappers as (msg: Buffer | string)[] | Buffer | string","Reject Blobs early — dgram only accepts string or ArrayBufferView"],"tags":["node-compat","dgram","validation","buffer"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}