{"record":{"id":"e2435cc458ad2832","repo":"grafana/k6","slug":"a-value-for-s-should-be-callable","errorCode":null,"errorMessage":"a value for '%s' should be callable","messagePattern":"a value for '(.+?)' should be callable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/websockets/websockets.go","lineNumber":255,"sourceCode":"\t\t\tcommon.Throw(rt, fmt.Errorf(\"not supported on-handler '%s'\", property))\n\t\t}\n\n\t\tmust(rt, w.obj.DefineAccessorProperty(\n\t\t\tproperty, rt.ToValue(func() sobek.Value {\n\t\t\t\treturn rt.ToValue(el.getOn)\n\t\t\t}), rt.ToValue(func(call sobek.FunctionCall) sobek.Value {\n\t\t\t\targ := call.Argument(0)\n\n\t\t\t\t// it's possible to unset handlers by setting them to null\n\t\t\t\tif common.IsNullish(arg) {\n\t\t\t\t\tel.setOn(nil)\n\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\n\t\t\t\tfn, isFunc := sobek.AssertFunction(arg)\n\t\t\t\tif !isFunc {\n\t\t\t\t\tcommon.Throw(rt, fmt.Errorf(\"a value for '%s' should be callable\", property))\n\t\t\t\t}\n\n\t\t\t\tel.setOn(func(v sobek.Value) (sobek.Value, error) { return fn(sobek.Undefined(), v) })\n\n\t\t\t\treturn nil\n\t\t\t}), sobek.FLAG_FALSE, sobek.FLAG_TRUE))\n\t}\n\n\tsetOn(\"onmessage\", w.eventListeners.getType(events.MESSAGE))\n\tsetOn(\"onerror\", w.eventListeners.getType(events.ERROR))\n\tsetOn(\"onopen\", w.eventListeners.getType(events.OPEN))\n\tsetOn(\"onclose\", w.eventListeners.getType(events.CLOSE))\n\tsetOn(\"onping\", w.eventListeners.getType(events.PING))\n\tsetOn(\"onpong\", w.eventListeners.getType(events.PONG))\n\n\tdefineReadyStateProperties(rt, w.obj)\n}\n","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/grafana/k6/blob/165bb3c1a492b7a4823907fe1e93a30645794737/internal/js/modules/k6/websockets/websockets.go#L237-L273","documentation":"Type guard in the WebSocket event-handler setter: on<event> (e.g., onopen, onmessage, onclose, onerror) was assigned a non-null value that is not a function. Setting the handler to null/undefined is allowed and unsets it, but any other non-callable value (number, string, object) is rejected, mirroring the browser behavior where event handler IDL attributes must be callbacks or null.","triggerScenarios":"Thrown at internal/js/modules/k6/websockets/websockets.go:244 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Assign a function to the on<event> property: ws.onmessage = (ev) => { ... }","Use ws.addEventListener('message', handler) as an alternative","Pass null instead of a non-function value when clearing a handler"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"165bb3c1a492b7a4823907fe1e93a30645794737","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}