{"record":{"id":"108fdbbba6ef78f4","repo":"grafana/k6","slug":"missing-argument-expected-arraybuffer","errorCode":null,"errorMessage":"missing argument, expected ArrayBuffer","messagePattern":"missing argument, expected ArrayBuffer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/ws/ws.go","lineNumber":348,"sourceCode":"\tif err := s.conn.WriteMessage(websocket.TextMessage, []byte(message)); err != nil {\n\t\ts.handleEvent(\"error\", s.rt.ToValue(err))\n\t}\n\n\tmetrics.PushIfNotDone(s.ctx, s.samplesOutput, metrics.Sample{\n\t\tTimeSeries: metrics.TimeSeries{\n\t\t\tMetric: s.builtinMetrics.WSMessagesSent,\n\t\t\tTags:   s.tagsAndMeta.Tags,\n\t\t},\n\t\tTime:     time.Now(),\n\t\tMetadata: s.tagsAndMeta.Metadata,\n\t\tValue:    1,\n\t})\n}\n\n// SendBinary writes the given ArrayBuffer message to the connection.\nfunc (s *Socket) SendBinary(message sobek.Value) {\n\tif message == nil {\n\t\tcommon.Throw(s.rt, errors.New(\"missing argument, expected ArrayBuffer\"))\n\t}\n\n\tmsg := message.Export()\n\tif ab, ok := msg.(sobek.ArrayBuffer); ok {\n\t\tif err := s.conn.WriteMessage(websocket.BinaryMessage, ab.Bytes()); err != nil {\n\t\t\ts.handleEvent(\"error\", s.rt.ToValue(err))\n\t\t}\n\t} else {\n\t\tvar jsType string\n\t\tswitch {\n\t\tcase sobek.IsNull(message), sobek.IsUndefined(message):\n\t\t\tjsType = message.String()\n\t\tdefault:\n\t\t\tjsType = message.ToObject(s.rt).Get(\"constructor\").ToObject(s.rt).Get(\"name\").String()\n\t\t}\n\t\tcommon.Throw(s.rt, fmt.Errorf(\"expected ArrayBuffer as argument, received: %s\", jsType))\n\t}\n","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/ws/ws.go#L330-L366","documentation":"Thrown by Socket.sendBinary() in the legacy k6/ws module when it is called with no argument at all. The Go method (internal/js/modules/k6/ws/ws.go:348) receives a nil sobek value for a missing argument and immediately throws 'missing argument, expected ArrayBuffer'. A present argument of the wrong type produces a different error naming the unsupported type.","triggerScenarios":"socket.sendBinary() with empty parentheses inside the ws.connect setup callback — e.g. refactoring dropped the buffer argument, or the variable holding the ArrayBuffer is not in scope and the call was left bare.","commonSituations":"Migrating scripts that used socket.send(...) with defaults; refactoring that moves the payload into another function while leaving the call site argumentless; copy-paste of the method name without the payload.","solutions":["Pass an ArrayBuffer: socket.sendBinary(new Uint8Array([1, 2, 3]).buffer)","If the payload is a view over a larger buffer, slice first: new Uint8Array(buf, byteOffset, length).slice().buffer","Prefer socket.send(...) for strings/objects — sendBinary is specifically the ArrayBuffer path"],"exampleFix":"// before\nsocket.sendBinary();\n\n// after\nsocket.sendBinary(new Uint8Array([1, 2, 3]).buffer);","handlingStrategy":"validation","validationCode":"function sendBinaryChecked(socket, payload) {\n  if (payload === undefined || payload === null) {\n    throw new TypeError('sendBinary requires an ArrayBuffer, e.g. new Uint8Array([...]).buffer');\n  }\n  if (!(payload instanceof ArrayBuffer)) {\n    payload = payload instanceof Uint8Array ? payload.slice().buffer : null;\n    if (payload === null) throw new TypeError('sendBinary requires an ArrayBuffer');\n  }\n  socket.sendBinary(payload);\n}","typeGuard":"function isArrayBuffer(v) {\n  return v instanceof ArrayBuffer;\n}","tryCatchPattern":null,"preventionTips":["Always construct the buffer at the call site: socket.sendBinary(new Uint8Array(data).buffer)","Remember views over a shared buffer must be sliced before .buffer is sent","Prefer socket.send() unless the payload must be a binary frame"],"tags":["websocket","k6-ws","sendbinary","arguments","arraybuffer"],"backgroundTag":"missing-required-argument","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}