{"record":{"id":"84fa6ee8875b47b3","repo":"denoland/deno","slug":"expected-data-to-be-a-string-buffer-uint8array","errorCode":null,"errorMessage":"Expected data to be a string, Buffer, Uint8Array, or ArrayBuffer","messagePattern":"Expected data to be a string, Buffer, Uint8Array, or ArrayBuffer","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/inspector.js","lineNumber":95,"sourceCode":"      TypedArrayPrototypeGetByteLength(buf),\n    );\n  }\n  if (TypedArrayPrototypeGetSymbolToStringTag(data) === \"Uint8Array\") {\n    return op_base64_encode_from_buffer(\n      data,\n      0,\n      TypedArrayPrototypeGetByteLength(data),\n    );\n  }\n  if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, data)) {\n    const view = new Uint8Array(data);\n    return op_base64_encode_from_buffer(\n      view,\n      0,\n      TypedArrayPrototypeGetByteLength(view),\n    );\n  }\n  throw new TypeError(\n    \"Expected data to be a string, Buffer, Uint8Array, or ArrayBuffer\",\n  );\n}\n\nclass Session extends EventEmitter {\n  #connection = null;\n  #nextId = 1;\n  #messageCallbacks = new SafeMap();\n  #pendingMessages = [];\n  #drainScheduled = false;\n  #isDraining = false;\n\n  connect() {\n    if (this.#connection) {\n      throw new ERR_INSPECTOR_ALREADY_CONNECTED(\"The inspector session\");\n    }\n    this.#connection = op_inspector_connect(\n      false,","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/inspector.js#L77-L113","documentation":"An internal helper in the node:inspector polyfill base64-encodes payload data (via op_base64_encode_from_buffer) before it is sent over the inspector protocol. It accepts strings, non-DataView typed arrays (Buffer/Uint8Array), and ArrayBuffer; every other value (number, plain object, DataView, null) falls through to a plain TypeError with no err.code property.","triggerScenarios":"Handing data of an unsupported type to inspector paths that serialize message/network payloads — e.g. a data field that is a plain object, number, boolean, null, or a DataView instead of string/Buffer/Uint8Array/ArrayBuffer.","commonSituations":"Porting Node inspector tooling where a wider set of coercible inputs happened to work; passing decoded JSON objects where the raw body (string or bytes) is expected.","solutions":["Serialize non-binary values yourself: JSON.stringify(value) or String(value) before passing them as data.","Convert binary to Uint8Array/Buffer; for a DataView use new Uint8Array(dv.buffer, dv.byteOffset, dv.byteLength).","Match on the TypeError message text when catching — there is no error code to test."],"exampleFix":"// before - data is a plain object\nemitWithPayload({ requestId: '1', data: { bytes: 4 } }); // internal encoder throws TypeError\n\n// after\nemitWithPayload({ requestId: '1', data: JSON.stringify({ bytes: 4 }) });","handlingStrategy":"type-guard","validationCode":"function encodeInspectorData(data) {\n  if (typeof data === 'string') return data;\n  if (ArrayBuffer.isView(data) && !(data instanceof DataView)) return data;\n  if (data instanceof ArrayBuffer) return new Uint8Array(data);\n  return Buffer.from(JSON.stringify(data));\n}","typeGuard":"function isInspectorEncodable(v) {\n  return typeof v === 'string' || v instanceof ArrayBuffer ||\n    (ArrayBuffer.isView(v) && !(v instanceof DataView));\n}","tryCatchPattern":null,"preventionTips":["Serialize objects to strings before handing them to inspector data fields.","Keep binary payloads as Buffer/Uint8Array, not DataView.","Remember this is a plain TypeError — match on message text, not a code."],"tags":["inspector","type-error","internal-api","node-compat"],"backgroundTag":"invalid-argument-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}