grafana/k6 · error

method to invoke cannot be empty

Error message

method to invoke cannot be empty

What it means

buildInvokeRequest validates the method name before looking it up: an empty string is rejected outright. A leading '/' is prepended if missing, but an empty method can never resolve, so it fails fast with this message.

Source

Thrown at internal/js/modules/k6/grpc/client.go:359

}

// 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 93accf6570)

Solutions

  1. Pass the fully qualified method name, e.g. '/package.Service/Method'
  2. Validate/normalize names from external data: if (!m) throw new Error(...) or skip the row
  3. Check argument order: invoke(method, request, params)

Example fix

// before
client.invoke(method, {}) // method is '' from bad data

// after
if (!method) throw new Error(`empty gRPC method for row ${i}`);
client.invoke(method, {});
Defensive patterns

Strategy: validation

Validate before calling

function validMethod(m) {
  return typeof m === 'string' && m.trim() !== '';
}

if (!validMethod(method)) throw new Error(`invalid gRPC method: ${JSON.stringify(method)}`);
client.invoke(method, req, params);

Type guard

/** @param {unknown} m @returns {m is string} */
const isMethodName = (m) => typeof m === 'string' && m.length > 0;

Prevention

When it happens

Trigger: client.invoke('') or client.invoke(undefinedVariableName) where the variable is an empty string; building the method name by concatenation that yields an empty string; asyncInvoke with an empty method.

Common situations: Method names read from JSON/CSV data or env variables that are blank for some rows; templating bugs producing empty strings; typos where the name is passed in the wrong argument slot.

Related errors


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