{"record":{"id":"718d0e00b619dc7d","repo":"grafana/k6","slug":"invalid-grpc-stream-s-client-w","errorCode":null,"errorMessage":"invalid GRPC Stream's client: %w","messagePattern":"invalid GRPC Stream's client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/grpc/grpc.go","lineNumber":117,"sourceCode":"\tmustAddServingStatus(\"HealthCheckServing\", healthpb.HealthCheckResponse_SERVING)\n\tmustAddServingStatus(\"HealthCheckNotServing\", healthpb.HealthCheckResponse_NOT_SERVING)\n\tmustAddServingStatus(\"HealthCheckServiceUnkown\", healthpb.HealthCheckResponse_SERVICE_UNKNOWN)\n}\n\n// Exports returns the exports of the grpc module.\nfunc (mi *ModuleInstance) Exports() modules.Exports {\n\treturn modules.Exports{\n\t\tNamed: mi.exports,\n\t}\n}\n\n// stream returns a new stream object\nfunc (mi *ModuleInstance) stream(c sobek.ConstructorCall) *sobek.Object {\n\trt := mi.vu.Runtime()\n\n\tclient, err := extractClient(c.Argument(0), rt)\n\tif err != nil {\n\t\tcommon.Throw(rt, fmt.Errorf(\"invalid GRPC Stream's client: %w\", err))\n\t}\n\n\tmethodName := sanitizeMethodName(c.Argument(1).String())\n\tmethodDescriptor, err := client.getMethodDescriptor(methodName)\n\tif err != nil {\n\t\tcommon.Throw(rt, fmt.Errorf(\"invalid GRPC Stream's method: %w\", err))\n\t}\n\n\tp, err := newCallParams(mi.vu, c.Argument(2))\n\tif err != nil {\n\t\tcommon.Throw(rt, fmt.Errorf(\"invalid GRPC Stream's parameters: %w\", err))\n\t}\n\n\tp.SetSystemTags(mi.vu.State(), client.addr, methodName)\n\n\tlogger := mi.vu.State().Logger.WithField(\"streamMethod\", methodName)\n\n\ts := &stream{","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/grpc/grpc.go#L99-L135","documentation":"The first argument of new grpc.Stream(client, methodName, params) must be a k6 gRPC Client instance. stream() passes it to extractClient(), which unwraps the JS value and type-asserts the native Go *Client; undefined, null, the grpc.Client class itself, or a look-alike object from another module fails the assertion and the constructor throws immediately.","triggerScenarios":"new grpc.Stream(undefined, ...) or calling Stream before any client was created; passing the class instead of an instance (new grpc.Stream(grpc.Client, ...)); passing an object that merely wraps the real client; passing a client from k6/http or another module.","commonSituations":"Refactors that moved client creation into a helper which returns undefined on an error path; copy-pasting a Stream example while the local variable has a different name; the client variable being shadowed in an inner scope.","solutions":["Create the client first and pass that instance: const client = new grpc.Client(); ...; new grpc.Stream(client, ...)","Check the variable you pass is the same one you called load()/connect() on and is in scope at the call site","Do not wrap the client in another object; Stream needs the raw k6/grpc Client"],"exampleFix":"// before\nconst stream = new grpc.Stream(client, '/pkg.Svc/Method'); // client is undefined here\n\n// after\nconst client = new grpc.Client();\nclient.load([], 'service.proto');\nclient.connect('localhost:8080');\nconst stream = new grpc.Stream(client, '/pkg.Svc/Method');","handlingStrategy":"type-guard","validationCode":"if (!isGrpcClient(client)) {\n  throw new Error(`grpc.Stream requires a k6 grpc.Client instance, got ${client}`);\n}\nconst stream = new grpc.Stream(client, METHOD);","typeGuard":"function isGrpcClient(v) {\n  return v != null && typeof v === 'object' && v instanceof grpc.Client;\n}","tryCatchPattern":null,"preventionTips":["Create and connect the client in the same scope where you build streams","Fail loudly if a client-factory helper returns undefined instead of passing it on","Avoid wrapper objects around the client; stream APIs need the raw instance"],"tags":["grpc","stream","client","type-error"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}