grafana/k6 · error
request cannot be nil
Error message
request cannot be nil
What it means
buildInvokeRequest requires a request value: a nil sobek.Value (the second argument missing entirely from the JS call) is rejected. Unlike some k6 APIs, no default empty message is synthesized -- even RPCs whose request type is google.protobuf.Empty must pass an explicit object.
Source
Thrown at internal/js/modules/k6/grpc/client.go:380
method = "/" + method
}
methodDesc := c.mds[method]
if methodDesc == nil {
return grpcReq, fmt.Errorf("method %q not found in file descriptors", method)
}
p, err := newCallParams(c.vu, params)
if err != nil {
return grpcReq, fmt.Errorf("invalid GRPC's client.invoke() parameters: %w", err)
}
// k6 GRPC Invoke's default timeout is 2 minutes
if p.Timeout == time.Duration(0) {
p.Timeout = 2 * time.Minute
}
if req == nil {
return grpcReq, errors.New("request cannot be nil")
}
object := req.ToObject(c.vu.Runtime())
var stack []*sobek.Object
normalized, err := normalizeNumberStrings(object, c.vu.Runtime(), stack)
if err != nil {
return grpcReq, fmt.Errorf("unable to normalize number strings: %w", err)
}
b, err := normalized.ToObject(c.vu.Runtime()).MarshalJSON()
if err != nil {
return grpcReq, fmt.Errorf("unable to serialise request object: %w", err)
}
p.SetSystemTags(state, c.addr, method)
return grpcext.InvokeRequest{View on GitHub (pinned to 93accf6570)
Solutions
- Always pass a request object, using {} for empty messages: client.invoke('/grpc.health.v1.Health/Check', {})
- For typed stubs, default the parameter: invoke(m, req ?? {})
Example fix
// before
client.invoke('/grpc.health.v1.Health/Check');
// after
client.invoke('/grpc.health.v1.Health/Check', {}); Defensive patterns
Strategy: validation
Validate before calling
client.invoke(method, req ?? {}); // request argument is mandatory; {} for Empty messages Prevention
- Always pass the second argument, even for Empty-request RPCs
- Default at wrapper level: const invoke = (m, r = {}) => client.invoke(m, r)
- Remember params is the third argument -- do not shift it into the request slot
When it happens
Trigger: client.invoke('/pkg.Svc/Method') with only one argument; client.asyncInvoke(method) without a request; the request argument dropped while refactoring call sites.
Common situations: Health checks and other Empty-request RPCs where users omit the argument because there is nothing to send; parameter object accidentally consumed as the request argument.
Related errors
- method to invoke cannot be empty
- invalid GRPC's client.invoke() parameters: %w
- no gRPC connection, you must call connect first
- cyclic reference to an object found
- empty gRPC client
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/52d2ca1cc2560170.
Report an issue: GitHub.