{"record":{"id":"16d8815190586762","repo":"grafana/k6","slug":"setinterval-requires-a-0-timeout-parameter-recei","errorCode":null,"errorMessage":"setInterval requires a >0 timeout parameter, received %.2f","messagePattern":"setInterval requires a >0 timeout parameter, received %\\.2f","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/ws/ws.go","lineNumber":454,"sourceCode":"\t\tcase <-s.done:\n\t\t\treturn\n\t\t}\n\t}()\n\n\treturn nil\n}\n\n// SetInterval executes the provided function inside the socket's event loop each interval time, which is\n// in ms\nfunc (s *Socket) SetInterval(fn sobek.Callable, intervalMs float64) error {\n\t// Starts a goroutine, blocks forever on the ticker and pushes the callable\n\t// back to the main loop through the scheduled channel.\n\t//\n\t// Intentionally not using the generic GetDurationValue() helper, since this\n\t// API is meant to use ms, similar to the original SetInterval() JS API.\n\td := time.Duration(intervalMs * float64(time.Millisecond))\n\tif d <= 0 {\n\t\treturn fmt.Errorf(\"setInterval requires a >0 timeout parameter, received %.2f\", intervalMs)\n\t}\n\tgo func() {\n\t\tticker := time.NewTicker(d)\n\t\tdefer ticker.Stop()\n\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase <-ticker.C:\n\t\t\t\tselect {\n\t\t\t\tcase s.scheduled <- fn:\n\t\t\t\tcase <-s.done:\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\tcase <-s.done:\n\t\t\t\treturn\n\t\t\t}\n\t\t}","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/ws/ws.go#L436-L472","documentation":"Returned by ws.Socket.SetInterval when the interval parameter, converted from milliseconds to a time.Duration, is <= 0. Identical guard to setTimeout: a non-positive interval would make the underlying time.Ticker panic or never fire, so it is rejected up front with the offending value shown to two decimals.","triggerScenarios":"Thrown at internal/js/modules/k6/ws/ws.go:454 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a positive millisecond value: socket.setInterval(fn, 500)","For a single delayed call use socket.setTimeout instead"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}