{"record":{"id":"7f06f19bfa1ef733","repo":"grafana/k6","slug":"unsupported-type-t","errorCode":null,"errorMessage":"unsupported type: %T","messagePattern":"unsupported type: %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/websockets/blob.go","lineNumber":130,"sourceCode":"\t\t\tcase []uint8:\n\t\t\t\t_, err = b.data.Write(v)\n\t\t\tcase []int8, []int16, []int32, []int64, []uint16, []uint32, []uint64, []float32, []float64:\n\t\t\t\terr = binary.Write(b.data, binary.LittleEndian, v)\n\t\t\tcase sobek.ArrayBuffer:\n\t\t\t\t_, err = b.data.Write(v.Bytes())\n\t\t\tcase *sobek.ArrayBuffer:\n\t\t\t\t_, err = b.data.Write(v.Bytes())\n\t\t\tcase string:\n\t\t\t\t_, err = b.data.WriteString(v)\n\t\t\tcase map[string]any:\n\t\t\t\tobj := call.Arguments[0].ToObject(rt).Get(strconv.FormatInt(int64(n), 10)).ToObject(rt)\n\t\t\t\tswitch {\n\t\t\t\tcase isDataView(obj, rt):\n\t\t\t\t\t_, err = b.data.Write(obj.Get(\"buffer\").Export().(sobek.ArrayBuffer).Bytes()) //nolint:forcetypeassert\n\t\t\t\tcase isBlob(obj, r.blobConstructor):\n\t\t\t\t\t_, err = b.data.Write(extractBytes(obj, rt))\n\t\t\t\tdefault:\n\t\t\t\t\terr = fmt.Errorf(\"unsupported type: %T\", part)\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\terr = fmt.Errorf(\"unsupported type: %T\", part)\n\t\t\t}\n\t\t\tif err != nil {\n\t\t\t\tcommon.Throw(rt, fmt.Errorf(\"failed to process [blobParts]: %w\", err))\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc (r *WebSocketsAPI) slice(call sobek.FunctionCall, b *blob, rt *sobek.Runtime) sobek.Value {\n\tvar (\n\t\tfrom int\n\t\tto   = b.data.Len()\n\t\tct   = \"\"\n\t)\n","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/websockets/blob.go#L112-L148","documentation":"While filling Blob data, parts that export to a Go map[string]any (i.e. JS objects) are only accepted when they are a DataView or a real Blob; every other object hits this 'unsupported type: map[string]interface {}' error, which is then rethrown as 'failed to process [blobParts]'.","triggerScenarios":"new ws.Blob([{ foo: 'bar' }]) with a plain object element; passing a JSON-parsed value (JSON.parse returns objects/maps); passing an object that merely duck-types a Blob but was not created by the same Blob constructor (instanceof check via blobConstructor fails); class instances whose export is a map.","commonSituations":"Trying to serialize an object into a Blob directly instead of JSON.stringify-ing it; wrapping third-party 'blob-like' objects from another module; passing {buffer, byteOffset} literal structures expecting DataView semantics; copy-pasting browser code that relies on structured cloning k6 does not implement.","solutions":["Serialize objects first: new Blob([JSON.stringify(obj)])","Only nest real Blob instances produced by the same ws.Blob constructor","For binary object data, convert to ArrayBuffer or Uint8Array before constructing the Blob"],"exampleFix":"// before\nconst b = new ws.Blob([{ name: 'k6', v: 1 }]); // object part -> unsupported type\n\n// after\nconst b = new ws.Blob([JSON.stringify({ name: 'k6', v: 1 })]);","handlingStrategy":"type-guard","validationCode":"function safeParts(parts) {\n  return parts.map(p => {\n    if (typeof p === 'string' || p instanceof ArrayBuffer || ArrayBuffer.isView(p)) return p;\n    if (p && typeof p === 'object' && !(p instanceof WS.Blob) && p.arrayBuffer === undefined) return JSON.stringify(p);\n    return p;\n  });\n}\nconst b = new WS.Blob(safeParts(parts));","typeGuard":"const isSupportedBlobPart = (p, BlobCtor) =>\n  typeof p === 'string' || p instanceof ArrayBuffer || ArrayBuffer.isView(p) || p instanceof BlobCtor;","tryCatchPattern":"try { b = new WS.Blob(parts); } catch (e) { if (/unsupported type: map/.test(e.message)) throw new Error('object in blobParts - JSON.stringify it first'); throw e; }","preventionTips":["Serialize plain objects to JSON strings before putting them in Blob parts","Only nest Blob objects created by the same WebSocket module constructor","Route all Blob construction through one helper that whitelists part types"],"tags":["websockets","blob","type-error","serialization"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}