{"record":{"id":"7fc604dac5b549ae","repo":"grafana/k6","slug":"settimeout-requires-a-0-timeout-parameter-receiv","errorCode":null,"errorMessage":"setTimeout requires a >0 timeout parameter, received %.2f","messagePattern":"setTimeout requires a >0 timeout parameter, received %\\.2f","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/ws/ws.go","lineNumber":425,"sourceCode":"\t\t\tTags:   s.tagsAndMeta.Tags,\n\t\t},\n\t\tTime:     pongTimestamp,\n\t\tMetadata: s.tagsAndMeta.Metadata,\n\t\tValue:    metrics.D(pongTimestamp.Sub(pingTimestamp)),\n\t})\n}\n\n// SetTimeout executes the provided function inside the socket's event loop after at least the provided\n// timeout, which is in ms, has elapsed\nfunc (s *Socket) SetTimeout(fn sobek.Callable, timeoutMs float64) error {\n\t// Starts a goroutine, blocks once on the timeout 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 SetTimeout() JS API.\n\td := time.Duration(timeoutMs * float64(time.Millisecond))\n\tif d <= 0 {\n\t\treturn fmt.Errorf(\"setTimeout requires a >0 timeout parameter, received %.2f\", timeoutMs)\n\t}\n\tgo func() {\n\t\tselect {\n\t\tcase <-time.After(d):\n\t\t\tselect {\n\t\t\tcase s.scheduled <- fn:\n\t\t\tcase <-s.done:\n\t\t\t\treturn\n\t\t\t}\n\n\t\tcase <-s.done:\n\t\t\treturn\n\t\t}\n\t}()\n\n\treturn nil\n}\n","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/ws/ws.go#L407-L443","documentation":"Returned by ws.Socket.SetTimeout when the timeout parameter, converted from milliseconds, is <= 0 (the guard rejects d <= 0 after duration conversion). The value is reported with two decimals so fractional or negative inputs are visible. The callback is never scheduled and the socket's timer machinery is untouched.","triggerScenarios":"Thrown at internal/js/modules/k6/ws/ws.go:425 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a positive millisecond value: socket.setTimeout(fn, 1000)","Guard dynamic values: socket.setTimeout(fn, Math.max(1, delay))"],"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"}