commaai/openpilot · error · URLFileException
Invalid whence value
Error message
Invalid whence value
What it means
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.
Source
Thrown at openpilot/tools/lib/url_file.py:209
if len(parts) != len(ranges):
raise URLFileException(f"Expected {len(ranges)} parts, got {len(parts)} ({self._url})")
return parts
def seekable(self) -> bool:
return True
def seek(self, pos: int, whence: int = 0) -> int:
pos = int(pos)
if whence == os.SEEK_SET:
self._pos = pos
elif whence == os.SEEK_CUR:
self._pos += pos
elif whence == os.SEEK_END:
length = self.get_length()
assert length != -1, "Cannot seek from end on unknown length file"
self._pos = length + pos
else:
raise URLFileException("Invalid whence value")
return self._pos
def tell(self) -> int:
return self._pos
@property
def name(self) -> str:
return self._url
os.register_at_fork(after_in_child=URLFile.reset)
View on GitHub (pinned to 516ec1e682)
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
Example fix
# before uf.seek(10, whence) # after import os assert whence in (os.SEEK_SET, os.SEEK_CUR, os.SEEK_END) uf.seek(10, whence)
Defensive patterns
Strategy: validation
Validate before calling
import os assert whence in (os.SEEK_SET, os.SEEK_CUR, os.SEEK_END)
Type guard
def is_valid_whence(w) -> bool:
import os
return w in (os.SEEK_SET, os.SEEK_CUR, os.SEEK_END) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Profile nickname must be 64 bytes or less
- Confirmation code required but not provided
- Invalid activation code format
- not a valid request or response
- -32000
AI-assisted analysis of commaai/openpilot@516ec1e682 (2026-08-15).
Data as JSON: /api/errors/697261f82e0c2adc.
Report an issue: GitHub.