grafana/k6 · error
invalid method type '%#v'
Error message
invalid method type '%#v'
What it means
In an array-form batch entry like [method, url, ...], the first element was not a string, so it cannot be an HTTP method. parseBatchRequest type-asserts data[0] to string after the array-length check passed; e.g. http.batch([42, 'http://example.com']) triggers it.
Source
Thrown at js/modules/k6/http/request.go:566
func (c *Client) parseBatchRequest(key any, val any) (*httpext.ParsedHTTPRequest, error) {
var (
method = http.MethodGet
ok bool
body, reqURL any
params sobek.Value
rt = c.moduleInstance.vu.Runtime()
)
switch data := val.(type) {
case []any:
// Handling of ["GET", "http://example.com/"]
dataLen := len(data)
if dataLen < 2 {
return nil, fmt.Errorf("invalid batch request '%#v'", data)
}
method, ok = data[0].(string)
if !ok {
return nil, fmt.Errorf("invalid method type '%#v'", data[0])
}
reqURL = data[1]
if dataLen > 2 {
body = data[2]
}
if dataLen > 3 {
params = rt.ToValue(data[3])
}
case map[string]any:
// Handling of {method: "GET", url: "https://test.k6.io"}
if _, ok := data["url"]; !ok {
return nil, fmt.Errorf("batch request %v doesn't have a url key", key)
}
reqURL = data["url"]
body = data["body"] // It's fine if it's missing, the map lookup will return
View on GitHub (pinned to 01ffac6f24)
Solutions
- Make the first element of each array-form batch entry a string HTTP method, e.g. ['GET', 'http://example.com']
- Use the object form {method: 'GET', url: '...'} where the method value is also a string
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at js/modules/k6/http/request.go:566 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/953af4413dbcb945.
Report an issue: GitHub.