{"record":{"id":"031edb153fdd35f0","repo":"grafana/k6","slug":"method-to-invoke-cannot-be-empty","errorCode":null,"errorMessage":"method to invoke cannot be empty","messagePattern":"method to invoke cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/grpc/client.go","lineNumber":359,"sourceCode":"}\n\n// buildInvokeRequest creates a new InvokeRequest from the given method name, request object and parameters\nfunc (c *Client) buildInvokeRequest(\n\tmethod string,\n\treq sobek.Value,\n\tparams sobek.Value,\n) (grpcext.InvokeRequest, error) {\n\tgrpcReq := grpcext.InvokeRequest{}\n\n\tstate := c.vu.State()\n\tif state == nil {\n\t\treturn grpcReq, common.NewInitContextError(\"invoking RPC methods in the init context is not supported\")\n\t}\n\tif c.conn == nil {\n\t\treturn grpcReq, errors.New(\"no gRPC connection, you must call connect first\")\n\t}\n\tif method == \"\" {\n\t\treturn grpcReq, errors.New(\"method to invoke cannot be empty\")\n\t}\n\tif method[0] != '/' {\n\t\tmethod = \"/\" + method\n\t}\n\tmethodDesc := c.mds[method]\n\tif methodDesc == nil {\n\t\treturn grpcReq, fmt.Errorf(\"method %q not found in file descriptors\", method)\n\t}\n\n\tp, err := newCallParams(c.vu, params)\n\tif err != nil {\n\t\treturn grpcReq, fmt.Errorf(\"invalid GRPC's client.invoke() parameters: %w\", err)\n\t}\n\n\t// k6 GRPC Invoke's default timeout is 2 minutes\n\tif p.Timeout == time.Duration(0) {\n\t\tp.Timeout = 2 * time.Minute\n\t}","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/grpc/client.go#L341-L377","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the fully qualified method name, e.g. '/package.Service/Method'","Validate/normalize names from external data: if (!m) throw new Error(...) or skip the row","Check argument order: invoke(method, request, params)"],"exampleFix":"// before\nclient.invoke(method, {}) // method is '' from bad data\n\n// after\nif (!method) throw new Error(`empty gRPC method for row ${i}`);\nclient.invoke(method, {});","handlingStrategy":"validation","validationCode":"function validMethod(m) {\n  return typeof m === 'string' && m.trim() !== '';\n}\n\nif (!validMethod(method)) throw new Error(`invalid gRPC method: ${JSON.stringify(method)}`);\nclient.invoke(method, req, params);","typeGuard":"/** @param {unknown} m @returns {m is string} */\nconst isMethodName = (m) => typeof m === 'string' && m.length > 0;","tryCatchPattern":null,"preventionTips":["Prefer fully qualified names with a leading slash: '/package.Service/Method'","Validate names coming from data files/env before the iteration loop, not per invoke","Keep argument order fixed: (method, request, params)"],"tags":["grpc","invoke","validation","method-name"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}