{"record":{"id":"2a22dff72aea8ec4","repo":"SeleniumHQ/selenium","slug":"property-name-cannot-be-less-than-0","errorCode":null,"errorMessage":"{property_name} cannot be less than 0","messagePattern":"(.+?) cannot be less than 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/common/print_page_options.py","lineNumber":364,"sourceCode":"                respective values in cm.\n\n        Example:\n            self.set_page_size(PageSize.A4)  # A4 predefined size\n            self.set_page_size({\"height\": 15.0, \"width\": 20.0})  # Custom size\n        \"\"\"\n        self._validate_num_property(\"height\", page_size[\"height\"])\n        self._validate_num_property(\"width\", page_size[\"width\"])\n        self._page[\"height\"] = page_size[\"height\"]\n        self._page[\"width\"] = page_size[\"width\"]\n        self._print_options[\"page\"] = self._page\n\n    def _validate_num_property(self, property_name: str, value: float) -> None:\n        \"\"\"Helper function to validate some of the properties.\"\"\"\n        if not isinstance(value, (int, float)):\n            raise ValueError(f\"{property_name} should be an integer or a float\")\n\n        if value < 0:\n            raise ValueError(f\"{property_name} cannot be less than 0\")\n","sourceCodeStart":346,"sourceCodeEnd":365,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/common/print_page_options.py#L346-L365","documentation":"After confirming a value is numeric, _validate_num_property rejects any value below zero. Page height/width, margins, and scale must be non-negative. A negative number raises ValueError naming the property. (Scale has its own narrower 0.1–2.0 range check that fires after this for the scale descriptor.)","triggerScenarios":"Setting print_options.set_page_size({'height': -5, 'width': 21}), page_height = -1.0, or margin_top = -2. Passing a sentinel like -1 meaning 'unset'.","commonSituations":"Using -1 as an 'unset' marker from config. Sign errors in calculations. Defaulting missing values to -1.","solutions":["Use 0 or a positive value; use None/omission for 'unset'.","Clamp negative inputs to 0 or skip the assignment when the value is negative."],"exampleFix":"# before\nprint_options.set_page_size({'height': -1, 'width': 21})  # -1 sentinel -> ValueError\n\n# after\nif h is not None and h >= 0:\n    print_options.set_page_size({'height': h, 'width': w})","handlingStrategy":"validation","validationCode":"if not isinstance(value, (int, float)) or value < 0:\n    raise ValueError(f'{name} must be a non-negative number')\n# then set","typeGuard":"def is_non_negative_number(v) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool) and v >= 0","tryCatchPattern":"try:\n    print_options.set_page_size(page_size)\nexcept ValueError:\n    page_size = {k: max(0.0, float(v)) for k, v in page_size.items()}\n    print_options.set_page_size(page_size)","preventionTips":["Do not use -1 as an 'unset' sentinel; use None and omit the call.","Clamp computed dimensions to >= 0."],"tags":["print","range","numeric","validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}