LogReader: more specific exceptions (#33914)

* more specific logreader exceptions

* huh

* fix
pull/33915/head
Shane Smiskol 6 months ago committed by GitHub
parent 61508e48a1
commit 2af9f68147
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      selfdrive/car/tests/test_models.py
  2. 10
      tools/lib/logreader.py

@ -22,7 +22,7 @@ from openpilot.selfdrive.selfdrived.selfdrived import SelfdriveD
from openpilot.selfdrive.pandad import can_capnp_to_list
from openpilot.selfdrive.test.helpers import read_segment_list
from openpilot.system.hardware.hw import DEFAULT_DOWNLOAD_CACHE_ROOT
from openpilot.tools.lib.logreader import LogReader
from openpilot.tools.lib.logreader import LogReader, LogsUnavailable
from openpilot.tools.lib.route import SegmentName
from panda.tests.libpanda import libpanda_py
@ -113,11 +113,9 @@ class TestCarModelBase(unittest.TestCase):
(SafetyModel.elm327, SafetyModel.noOutput):
cls.car_safety_mode_frame = len(can_msgs)
if len(can_msgs) > int(50 / DT_CTRL):
assert len(can_msgs) > int(50 / DT_CTRL), "no can data found"
return car_fw, can_msgs, experimental_long
raise Exception("no can data found")
@classmethod
def get_testing_data(cls):
test_segs = (2, 1, 0)
@ -130,7 +128,7 @@ class TestCarModelBase(unittest.TestCase):
try:
lr = LogReader(segment_range)
return cls.get_testing_data_from_logreader(lr)
except Exception:
except (LogsUnavailable, AssertionError):
pass
raise Exception(f"Route: {repr(cls.test_route.route)} with segments: {test_segs} not found or no CAN msgs found. Is it uploaded and public?")

@ -49,7 +49,7 @@ class _LogFileReader:
_, ext = os.path.splitext(urllib.parse.urlparse(fn).path)
if ext not in ('', '.bz2', '.zst'):
# old rlogs weren't compressed
raise Exception(f"unknown extension {ext}")
raise ValueError(f"unknown extension {ext}")
with FileReader(fn) as f:
dat = f.read()
@ -99,6 +99,10 @@ Source = Callable[[SegmentRange, ReadMode], list[LogPath]]
InternalUnavailableException = Exception("Internal source not available")
class LogsUnavailable(Exception):
pass
@cache
def default_valid_file(fn: LogPath) -> bool:
return fn is not None and file_exists(fn)
@ -128,7 +132,7 @@ def apply_strategy(mode: ReadMode, rlog_paths: list[LogPath], qlog_paths: list[L
return auto_strategy(rlog_paths, qlog_paths, False, valid_file)
elif mode == ReadMode.AUTO_INTERACTIVE:
return auto_strategy(rlog_paths, qlog_paths, True, valid_file)
raise Exception(f"invalid mode: {mode}")
raise ValueError(f"invalid mode: {mode}")
def comma_api_source(sr: SegmentRange, mode: ReadMode) -> list[LogPath]:
@ -224,7 +228,7 @@ def auto_source(sr: SegmentRange, mode=ReadMode.RLOG, sources: list[Source] = No
except Exception as e:
exceptions[source.__name__] = e
raise Exception("auto_source could not find any valid source, exceptions for sources:\n - " +
raise LogsUnavailable("auto_source could not find any valid source, exceptions for sources:\n - " +
"\n - ".join([f"{k}: {repr(v)}" for k, v in exceptions.items()]))

Loading…
Cancel
Save