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

  1. Always pass a request object, using {} for empty messages: client.invoke('/grpc.health.v1.Health/Check', {})
  2. 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

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


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/52d2ca1cc2560170. Report an issue: GitHub.