{"record":{"id":"72d31a7a49709b11","repo":"SeleniumHQ/selenium","slug":"interval-must-be-a-positive-number","errorCode":null,"errorMessage":"interval must be a positive number","messagePattern":"interval must be a positive number","errorType":"validation","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/websocket_connection.py","lineNumber":88,"sourceCode":"                        if pv is not None:\n                            result[_snake_to_camel(pf.name)] = self._convert(pv)\n                else:\n                    result[camel_key] = self._convert(value)\n            return result\n        return super().default(o)\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass WebSocketConnection:\n    _max_log_message_size = 9999\n\n    def __init__(self, url, timeout, interval):\n        if not isinstance(timeout, (int, float)) or timeout < 0:\n            raise WebDriverException(\"timeout must be a positive number\")\n        if not isinstance(interval, (int, float)) or timeout < 0:\n            raise WebDriverException(\"interval must be a positive number\")\n\n        self.url = url\n        self.response_wait_timeout = timeout\n        self.response_wait_interval = interval\n\n        self.callbacks = {}\n        self.session_id = None\n        self._id = 0\n        self._id_lock = threading.Lock()\n        self._messages = {}\n        self._started = False\n\n        self._start_ws()\n        self._wait_until(lambda: self._started)\n\n    def close(self):\n        # Close the socket first so ``run_forever`` returns; only then join the\n        # thread. Joining first would block for the full ``response_wait_timeout``","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/websocket_connection.py#L70-L106","documentation":"Raised by WebSocketConnection.__init__ while validating the polling interval used to wait for BiDi command responses. IMPORTANT BUG: the second guard re-checks `timeout < 0` instead of `interval < 0`, so the text 'interval must be a positive number' is misleading. In practice it fires when `interval` is not an int/float, or (due to the bug) when `timeout` is negative even though `interval` is valid. A genuinely negative `interval` currently does NOT raise.","triggerScenarios":"1) Constructing WebSocketConnection with a non-numeric interval (string, None, or a timedelta object). 2) Passing a negative `timeout` together with a valid `interval` - the buggy condition (`timeout < 0`) triggers and reports the wrong field.","commonSituations":"Defaulting interval from an unset config value (None); passing a timedelta instead of a raw float; reusing the timeout literal for both args. The misleading message routinely sends developers to debug the interval value when timeout is the real culprit.","solutions":["Pass `interval` as a positive int or float (seconds), distinct from `timeout`.","Ensure `timeout` is also non-negative, since the buggy guard will surface the interval error for a negative timeout.","File/track the upstream defect: the interval guard must read `interval < 0`, not `timeout < 0`."],"exampleFix":"# before\nWebSocketConnection(url, timeout=10, interval=\"0.5\")\n\n# after\nWebSocketConnection(url, timeout=10, interval=0.5)","handlingStrategy":"validation","validationCode":"def valid_interval(v) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool) and v > 0\n\n# also ensure timeout >= 0 to avoid the misreported message\nassert valid_interval(interval) and (isinstance(timeout, (int, float)) and timeout >= 0)","typeGuard":"def is_positive_number(v) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool) and v > 0","tryCatchPattern":null,"preventionTips":["Keep `interval` and `timeout` as separate, typed config values.","Treat any 'interval must be a positive number' as also suspecting a negative timeout until the upstream bug is fixed."],"tags":["bidi","validation","bug","websocket","python"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}