{"record":{"id":"58d6cd546995c40d","repo":"grafana/k6","slug":"invalid-type-t-it-needs-to-be-a-string-or-arrayb","errorCode":null,"errorMessage":"invalid type %T, it needs to be a string or ArrayBuffer","messagePattern":"invalid type %T, it needs to be a string or ArrayBuffer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"js/common/util.go","lineNumber":32,"sourceCode":"\tif e, ok := err.(*sobek.Exception); ok { //nolint:errorlint // we don't really want to unwrap here\n\t\tpanic(e)\n\t}\n\tpanic(rt.NewGoError(err)) // this catches the stack unlike rt.ToValue\n}\n\n// GetReader tries to return an io.Reader value from an exported Sobek value.\nfunc GetReader(data any) (io.Reader, error) {\n\tswitch r := data.(type) {\n\tcase string:\n\t\treturn bytes.NewBufferString(r), nil\n\tcase []byte:\n\t\treturn bytes.NewBuffer(r), nil\n\tcase io.Reader:\n\t\treturn r, nil\n\tcase sobek.ArrayBuffer:\n\t\treturn bytes.NewBuffer(r.Bytes()), nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid type %T, it needs to be a string or ArrayBuffer\", data)\n\t}\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\n// ToString tries to return a string from compatible types.","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/js/common/util.go#L14-L50","documentation":"A JS API expected data convertible to an io.Reader (string, []byte, ArrayBuffer or a reader), but the exported value had another Go type. GetReader's default branch names the actual type; used e.g. for summary/external data input.","triggerScenarios":"Thrown at js/common/util.go:32 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a string or ArrayBuffer instead of the unsupported type","Convert the value in the script, e.g. JSON.stringify objects before passing them"],"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":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}