{"record":{"id":"3c3bf9b2139e2919","repo":"grafana/k6","slug":"handler-for-q-event-isn-t-a-callable-function","errorCode":null,"errorMessage":"handler for %q event isn't a callable function","messagePattern":"handler for %q event isn't a callable function","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/grpc/stream.go","lineNumber":308,"sourceCode":"\t\t}\n\t}\n}\n\nfunc (s *stream) processSendError(err error) {\n\tif errors.Is(err, io.EOF) {\n\t\ts.logger.WithError(err).Debug(\"skip sending a message stream is cancelled/finished\")\n\t\terr = nil\n\t}\n\n\ts.tq.Queue(func() error {\n\t\treturn s.closeWithError(err)\n\t})\n}\n\n// on registers a handler for a certain event type\nfunc (s *stream) on(event string, handler func(sobek.Value, sobek.Value) (sobek.Value, error)) {\n\tif handler == nil {\n\t\tcommon.Throw(s.vu.Runtime(), fmt.Errorf(\"handler for %q event isn't a callable function\", event))\n\t}\n\n\tif err := s.eventListeners.add(event, s.wrapUnderCurrentMetricContext(handler)); err != nil {\n\t\ts.vu.State().Logger.Warnf(\"can't register %s event handler: %s\", event, err)\n\t}\n}\n\n// Stream listeners run outside Sobek's promise machinery.\nfunc (s *stream) wrapUnderCurrentMetricContext(\n\tfn func(sobek.Value, sobek.Value) (sobek.Value, error),\n) func(sobek.Value, sobek.Value) (sobek.Value, error) {\n\tif !common.AsyncMetricContextEnabled(s.vu.State()) {\n\t\treturn fn\n\t}\n\tcaptured := common.CaptureMetricContext(s.vu.State())\n\treturn func(v, metadata sobek.Value) (sobek.Value, error) {\n\t\treturn common.RunWithMetricContext(captured, func() (sobek.Value, error) {\n\t\t\treturn fn(v, metadata)","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/grpc/stream.go#L290-L326","documentation":"Thrown by the stream's `on` method when the resolved handler for an event is nil — i.e. the value passed to onEvent/on(event, handler) could not be converted to a callable Go function. This is a script authoring error: the handler argument is missing or is not a JavaScript function at all, so the runtime throws immediately via common.Throw.","triggerScenarios":"Thrown at internal/js/modules/k6/grpc/stream.go:308 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a function reference as the handler, e.g. stream.onEvent('data', (msg) => { ... })","Make sure the handler function is defined before registering it and not shadowed by an undefined variable"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-09-20T22:01:45.163Z","contentChangedAt":"2026-09-20T22:01:45.163Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}