{"record":{"id":"80dd296d830a5957","repo":"grafana/k6","slug":"invalid-type-t-expected-string-byte-or-arrayb","errorCode":null,"errorMessage":"invalid type %T, expected string, []byte or ArrayBuffer","messagePattern":"invalid type %T, expected string, \\[\\]byte or ArrayBuffer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/types.go","lineNumber":35,"sourceCode":"// byteLength is a type alias for the length of a byte slice.\ntype byteLength int\n\n// asBitLength returns the length of the byte slice in bits.\nfunc (b byteLength) asBitLength() bitLength {\n\treturn bitLength(b) * 8\n}\n\n// ToBytes tries to return a byte slice from compatible types.\nfunc ToBytes(data any) ([]byte, error) {\n\tswitch dt := data.(type) {\n\tcase []byte:\n\t\treturn dt, nil\n\tcase string:\n\t\treturn []byte(dt), nil\n\tcase sobek.ArrayBuffer:\n\t\treturn dt.Bytes(), nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid type %T, expected string, []byte or ArrayBuffer\", data)\n\t}\n}\n","sourceCodeStart":17,"sourceCodeEnd":38,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/webcrypto/types.go#L17-L38","documentation":"Returned by the webcrypto ToBytes helper when its argument is none of the three accepted types. The switch accepts []byte (internal), string, and sobek.ArrayBuffer; any other JS value — numbers, plain objects, TypedArrays that are not ArrayBuffers, null — hits the default branch and the actual Go type is reported. Typically fires when crypto APIs receive an unsupported data representation.","triggerScenarios":"Thrown at internal/js/modules/k6/webcrypto/types.go:35 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a string or an ArrayBuffer; for TypedArrays use .buffer to obtain the underlying ArrayBuffer","Convert other types explicitly, e.g. String(x) or new TextEncoder().encode(x).buffer"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}