Skip to content

Commit

Permalink
fix: loguru exception handling for invalid recordings (#361)
Browse files Browse the repository at this point in the history
* raise ValueError

* improve exception handling

* Update crud.py

* use assert

* reorganize catch

* Update openadapt/replay.py

* Update openadapt/visualize.py

* Update openadapt/events.py

* Update openadapt/crud.py

---------

Co-authored-by: Richard Abrich <[email protected]>
  • Loading branch information
0dm and abrichr authored Jul 17, 2023
1 parent 74e4af4 commit 7aba45b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions openadapt/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def _get(table, recording_timestamp):


def get_action_events(recording):
assert recording, "Invalid recording."
action_events = _get(ActionEvent, recording.timestamp)
# filter out stop sequences listed in STOP_SEQUENCES and Ctrl + C
filter_stop_sequences(action_events)
Expand Down Expand Up @@ -227,11 +228,12 @@ def get_screenshots(recording, precompute_diffs=False):

for prev, cur in zip(screenshots, screenshots[1:]):
cur.prev = prev
screenshots[0].prev = screenshots[0]
if screenshots:
screenshots[0].prev = screenshots[0]

# TODO: store diffs
if precompute_diffs:
logger.info(f"precomputing diffs...")
logger.info("precomputing diffs...")
[(screenshot.diff, screenshot.diff_mask) for screenshot in screenshots]

return screenshots
Expand Down
1 change: 1 addition & 0 deletions openadapt/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def get_events(
logger.debug(f"raw_action_event_dicts=\n{pformat(raw_action_event_dicts)}")

num_action_events = len(action_events)
assert num_action_events > 0, "No action events found."
num_window_events = len(window_events)
num_screenshots = len(screenshots)

Expand Down
2 changes: 1 addition & 1 deletion openadapt/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def read_mouse_events(
terminate_event.wait()
mouse_listener.stop()


@logger.catch
@trace(logger)
def record(
task_description: str,
Expand Down
2 changes: 1 addition & 1 deletion openadapt/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

LOG_LEVEL = "INFO"


@logger.catch
def replay(
strategy_name: str,
timestamp: Union[str, None] = None,
Expand Down
2 changes: 1 addition & 1 deletion openadapt/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def dict2html(obj, max_children=MAX_TABLE_CHILDREN, max_len=MAX_TABLE_STR_LEN):
html_str = head + middle + tail
return html_str


@logger.catch
def main():
configure_logging(logger, LOG_LEVEL)

Expand Down

0 comments on commit 7aba45b

Please sign in to comment.