grafana/k6 · error
method to invoke cannot be empty
Error message
method to invoke cannot be empty
What it means
buildInvokeRequest validates the method string right after the connection check: an empty method name cannot identify any RPC, so it is rejected before the method-descriptor lookup. (A non-empty but unknown method gets a different error: 'method %q not found in file descriptors'.)
Solutions
- Pass the fully-qualified method as 'package.Service/Method' (leading '/' is added automatically if missing).
- When method names come from data, validate them first: if (!method) throw new Error('method name required').
- If you get 'method not found in file descriptors' instead, the name is fine but the proto was not loaded - check client.load().
Example fix
// before
client.invoke('', { name: 'k6' }); // throws
// after
client.invoke('hello.HelloService/SayHello', { name: 'k6' }); Defensive patterns
Strategy: type-guard
Validate before calling
function invokeGrpc(client, method, req) {
if (typeof method !== 'string' || method.trim() === '') {
throw new TypeError(`gRPC method must be a non-empty 'package.Service/Method' string`);
}
return client.invoke(method, req);
} Type guard
const isGrpcMethod = (m) => typeof m === 'string' && m.trim().length > 0;
Try / catch
try {
client.invoke(method, req);
} catch (e) {
if (/cannot be empty/.test(e.message)) {
throw new Error(`method name was empty - check the config source: ${JSON.stringify(methodCfg)}`);
}
throw e;
} Prevention
- Centralize method names in a constants object so typos surface at review.
- When methods come from data/config, validate them in init before the test starts.
When it happens
Trigger: client.invoke('', req) with a literal empty string, or a computed method name that is empty because of a typo/failed lookup (e.g. methods[i] where i is out of range, or a config field that is missing).
Common situations: Building the method name from config or a loop over an empty array; refactoring that renames a constant to undefined; passing the request payload and method in swapped order so the first argument is an object coerced oddly; strings with only whitespace still count as non-empty and fail later at the descriptor lookup.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- no gRPC connection, you must call connect first
- a function is expected as the second argument of…
- canceled by client (k6)
- cannot be null or undefined
- empty name provided to SharedArray's constructor
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/031edb153fdd35f0.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/grpc/client.go:390
}
// buildInvokeRequest creates a new InvokeRequest from the given method name, request object and parameters
func (c *Client) buildInvokeRequest(
method string,
req sobek.Value,
params sobek.Value,
) (grpcext.InvokeRequest, error) {
grpcReq := grpcext.InvokeRequest{}
state := c.vu.State()
if state == nil {
return grpcReq, common.NewInitContextError("invoking RPC methods in the init context is not supported")
}
if c.conn == nil {
return grpcReq, errors.New("no gRPC connection, you must call connect first")
}
if method == "" {
return grpcReq, errors.New("method to invoke cannot be empty")
}
if method[0] != '/' {
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
}View on GitHub (pinned to 8d06114777)