{"record":{"id":"3d72e50c427eb51e","repo":"grafana/k6","slug":"http-batch-accepts-only-an-array-or-an-object-of","errorCode":null,"errorMessage":"http.batch() accepts only an array or an object of requests","messagePattern":"http\\.batch\\(\\) accepts only an array or an object of requests","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"js/modules/k6/http/request.go","lineNumber":504,"sourceCode":"\t\tresults[key] = c.responseFromHTTPext(resp)\n\t\ti++\n\t}\n\n\treturn batchReqs, results, nil\n}\n\n// Batch makes multiple simultaneous HTTP requests. The provideds reqsV should be an array of request\n// objects. Batch returns an array of responses and/or error\nfunc (c *Client) Batch(reqsV ...sobek.Value) (any, error) {\n\tstate := c.moduleInstance.vu.State()\n\tif state == nil {\n\t\treturn nil, ErrBatchForbiddenInInitContext\n\t}\n\n\tif len(reqsV) == 0 {\n\t\treturn nil, fmt.Errorf(\"no argument was provided to http.batch()\")\n\t} else if len(reqsV) > 1 {\n\t\treturn nil, fmt.Errorf(\"http.batch() accepts only an array or an object of requests\")\n\t}\n\tvar (\n\t\terr       error\n\t\tbatchReqs []httpext.BatchParsedHTTPRequest\n\t\tresults   any // either []*Response or map[string]*Response\n\t)\n\n\tswitch v := reqsV[0].Export().(type) {\n\tcase []any:\n\t\tbatchReqs, results, err = c.prepareBatchArray(v)\n\tcase map[string]any:\n\t\tbatchReqs, results, err = c.prepareBatchObject(v)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid http.batch() argument type %T\", v)\n\t}\n\n\tif err != nil {\n\t\tif state.Options.Throw.Bool {","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/js/modules/k6/http/request.go#L486-L522","documentation":"Batch accepts exactly one argument which must be an array or an object of request specs; more than one variadic argument triggers this error. It's an arity/type check protecting against http.batch(req1, req2) misuse — requests must be collected in a single array or object.","triggerScenarios":"Thrown at js/modules/k6/http/request.go:504 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Combine all requests into a single array or object argument","Remove extra arguments"],"exampleFix":null,"handlingStrategy":"validation","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"}