{"record":{"id":"10217a2d8d9eff99","repo":"grafana/k6","slug":"failed-to-process-blobparts-w","errorCode":null,"errorMessage":"failed to process [blobParts]: %w","messagePattern":"failed to process \\[blobParts\\]: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/websockets/blob.go","lineNumber":32,"sourceCode":")\n\ntype blob struct {\n\ttyp  string\n\tdata *bytes.Buffer\n}\n\nfunc (b *blob) text() string {\n\treturn b.data.String()\n}\n\nfunc (r *WebSocketsAPI) blob(call sobek.ConstructorCall) *sobek.Object {\n\trt := r.vu.Runtime()\n\n\tb := &blob{data: new(bytes.Buffer)}\n\tvar blobParts []any\n\tif len(call.Arguments) > 0 {\n\t\tif err := rt.ExportTo(call.Arguments[0], &blobParts); err != nil {\n\t\t\tcommon.Throw(rt, fmt.Errorf(\"failed to process [blobParts]: %w\", err))\n\t\t}\n\t}\n\n\tif len(blobParts) > 0 {\n\t\tr.fillData(b, blobParts, call)\n\t}\n\n\tif len(call.Arguments) > 1 && !sobek.IsUndefined(call.Arguments[1]) {\n\t\topts := call.Arguments[1]\n\t\tif !isObject(opts) {\n\t\t\tcommon.Throw(rt, errors.New(\"[options] must be an object\"))\n\t\t}\n\n\t\ttypeOpt := opts.ToObject(rt).Get(\"type\")\n\t\tif !sobek.IsUndefined(typeOpt) {\n\t\t\tb.typ = typeOpt.String()\n\t\t}\n\t}","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/websockets/blob.go#L14-L50","documentation":"The WebSocket module's Blob constructor (new ws.Blob(...)) exports its first argument into a []any via sobek's ExportTo. If that argument is not an array (string, number, object, null, undefined-with-extra-args), the export fails and k6 throws this error, wrapping sobek's conversion message.","triggerScenarios":"Calling new WebSocket Blob with a non-array blobParts: new Blob('hello'), new Blob({text:'hello'}), new Blob(42). Only new Blob([...]) with an actual JS array (or no first argument at all) is valid; a TypedArray of parts is also rejected because it is not a plain array.","commonSituations":"Porting browser code where a string shorthand was never valid anyway but the error is unfamiliar; passing a single Buffer-like value instead of wrapping it in an array; a variable that is undefined after a failed lookup being spread into the constructor; migrating scripts from the experimental websockets API with changed signatures.","solutions":["Always wrap parts in an array literal: new Blob([value])","If parts come from a variable, normalize first: const parts = Array.isArray(v) ? v : [v]","Check for undefined before constructing and pass an explicit empty array for an empty Blob"],"exampleFix":"// before\nconst b = new ws.Blob(someString); // TypeError: failed to process [blobParts]\n\n// after\nconst b = new ws.Blob([someString]);","handlingStrategy":"validation","validationCode":"function makeBlob(parts) {\n  const arr = parts === undefined ? [] : parts;\n  if (!Array.isArray(arr)) throw new TypeError('blobParts must be an array');\n  return new WS.Blob(arr);\n}","typeGuard":"const isPartsArray = v => v === undefined || Array.isArray(v);","tryCatchPattern":"try { b = new WS.Blob(parts); } catch (e) { if (/blobParts/.test(e.message)) throw new TypeError('wrap parts in an array: new Blob([value])'); throw e; }","preventionTips":["Always use the array form new Blob([x]) even for a single part","When parts come from variables, normalize: Array.isArray(v) ? v : [v]","Cover Blob construction in a small unit check at script start so signature mistakes fail immediately"],"tags":["websockets","blob","type-error","constructor"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}