{"record":{"id":"697261f82e0c2adc","repo":"commaai/openpilot","slug":"invalid-whence-value","errorCode":null,"errorMessage":"Invalid whence value","messagePattern":"Invalid whence value","errorType":"validation","errorClass":"URLFileException","httpStatus":null,"severity":"error","filePath":"openpilot/tools/lib/url_file.py","lineNumber":209,"sourceCode":"    if len(parts) != len(ranges):\n      raise URLFileException(f\"Expected {len(ranges)} parts, got {len(parts)} ({self._url})\")\n    return parts\n\n  def seekable(self) -> bool:\n    return True\n\n  def seek(self, pos: int, whence: int = 0) -> int:\n    pos = int(pos)\n    if whence == os.SEEK_SET:\n      self._pos = pos\n    elif whence == os.SEEK_CUR:\n      self._pos += pos\n    elif whence == os.SEEK_END:\n      length = self.get_length()\n      assert length != -1, \"Cannot seek from end on unknown length file\"\n      self._pos = length + pos\n    else:\n      raise URLFileException(\"Invalid whence value\")\n    return self._pos\n\n  def tell(self) -> int:\n    return self._pos\n\n  @property\n  def name(self) -> str:\n    return self._url\n\n\nos.register_at_fork(after_in_child=URLFile.reset)\n","sourceCodeStart":191,"sourceCodeEnd":221,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/openpilot/tools/lib/url_file.py#L191-L221","documentation":"URLFile.seek only handles the three standard whence values: os.SEEK_SET (0), SEEK_CUR (1), SEEK_END (2). Anything else — e.g. passing a string, a typo'd constant, or a non-standard whence — raises. Note pos is int()-coerced, but whence is compared literally.","triggerScenarios":"Calling uf.seek(n, 3), uf.seek(n, 'start'), or passing whence from an unvalidated variable. Also seek(..., SEEK_END) with unknown length hits the adjacent assert instead.","commonSituations":"Code adapted from io implementations that accept extra whence values; passing numpy ints or enum values that don't equal 0/1/2; user-supplied seek parameters.","solutions":["Use os.SEEK_SET / os.SEEK_CUR / os.SEEK_END (or 0/1/2) only","Validate/normalize whence before calling seek when it comes from external input","For seek-from-end, ensure the file length is known (HEAD succeeded) or the adjacent assert will fire"],"exampleFix":"# before\nuf.seek(10, whence)\n\n# after\nimport os\nassert whence in (os.SEEK_SET, os.SEEK_CUR, os.SEEK_END)\nuf.seek(10, whence)","handlingStrategy":"validation","validationCode":"import os\nassert whence in (os.SEEK_SET, os.SEEK_CUR, os.SEEK_END)","typeGuard":"def is_valid_whence(w) -> bool:\n    import os\n    return w in (os.SEEK_SET, os.SEEK_CUR, os.SEEK_END)","tryCatchPattern":null,"preventionTips":["Always pass os.SEEK_* constants, never magic numbers or strings","Normalize external seek parameters before forwarding to URLFile","Remember SEEK_END requires a known file length"],"tags":["api-misuse","file-io","url-file","validation"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}