grafana/k6 · error

invalid http.batch() argument type %T

Error message

invalid http.batch() argument type %T

What it means

After Export(), the single batch argument must be []any or map[string]any; any other JS type (string, number, function...) reaches the default case. Type validation on http.batch()'s argument — only arrays and objects of request definitions are supported.

Source

Thrown at js/modules/k6/http/request.go:518

	if len(reqsV) == 0 {
		return nil, fmt.Errorf("no argument was provided to http.batch()")
	} else if len(reqsV) > 1 {
		return nil, fmt.Errorf("http.batch() accepts only an array or an object of requests")
	}
	var (
		err       error
		batchReqs []httpext.BatchParsedHTTPRequest
		results   any // either []*Response or map[string]*Response
	)

	switch v := reqsV[0].Export().(type) {
	case []any:
		batchReqs, results, err = c.prepareBatchArray(v)
	case map[string]any:
		batchReqs, results, err = c.prepareBatchObject(v)
	default:
		return nil, fmt.Errorf("invalid http.batch() argument type %T", v)
	}

	if err != nil {
		if state.Options.Throw.Bool {
			return nil, err
		}
		state.Logger.WithField("error", err).Warn("A batch request failed")
		return results, nil
	}

	reqCount := len(batchReqs)
	errs := httpext.MakeBatchRequests(
		c.moduleInstance.vu.Context(), state, batchReqs, reqCount,
		int(state.Options.Batch.Int64), int(state.Options.BatchPerHost.Int64),
	)

	for range reqCount {
		if e := <-errs; e != nil && err == nil { // Save only the first error

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Pass an array like ['url1', ['POST','url2','body']] or an object {req1: 'url1'}
  2. Wrap individual requests in arrays/objects rather than passing raw values
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at js/modules/k6/http/request.go:518 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/b08cfeebeaf40b18. Report an issue: GitHub.