Skip to content

Commit

Permalink
WIP store failed_command in commands store
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Feb 8, 2024
1 parent 4cbcdc2 commit 690f5aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
19 changes: 11 additions & 8 deletions api/src/opentrons/protocol_engine/state/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class CommandState:
are stored on the individual commands themselves.
"""

failed_command: Optional[CommandEntry]
"""The command, if any, that made the run fail."""

finish_error: Optional[ErrorOccurrence]
"""The error that happened during the post-run finish steps (homing & dropping tips), if any."""

Expand Down Expand Up @@ -189,6 +192,7 @@ def __init__(
commands_by_id=OrderedDict(),
run_error=None,
finish_error=None,
failed_command=None,
run_completed_at=None,
run_started_at=None,
latest_command_hash=None,
Expand Down Expand Up @@ -283,6 +287,7 @@ def handle_action(self, action: Action) -> None: # noqa: C901
),
)

self._state.failed_command = prev_entry
if prev_entry.command.intent == CommandIntent.SETUP:
other_command_ids_to_fail = [
*[i for i in self._state.queued_setup_command_ids],
Expand Down Expand Up @@ -466,14 +471,12 @@ def get_slice(
cursor = commands_by_id[running_command_id].index
elif len(queued_command_ids) > 0:
cursor = commands_by_id[queued_command_ids.head()].index - 1
elif self._state.run_result and self._state.run_result == RunResult.FAILED:
# failed command only contains the error that occurred
last_executed = next(
command_id
for command_id, command in self._state.commands_by_id.items()
if command.command.error
)
cursor = commands_by_id[last_executed].index
elif (
self._state.run_result
and self._state.run_result == RunResult.FAILED
and self._state.failed_command
):
cursor = self._state.failed_command.index
else:
cursor = total_length - length

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ def test_command_store_handles_pause_action(pause_source: PauseSource) -> None:
commands_by_id=OrderedDict(),
run_error=None,
finish_error=None,
failed_command=None,
latest_command_hash=None,
stopped_by_estop=False,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get_command_view(
queued_command_ids: Sequence[str] = (),
queued_setup_command_ids: Sequence[str] = (),
run_error: Optional[errors.ErrorOccurrence] = None,
failed_command: Optional[CommandEntry] = None,
finish_error: Optional[errors.ErrorOccurrence] = None,
commands: Sequence[cmd.Command] = (),
latest_command_hash: Optional[str] = None,
Expand All @@ -67,6 +68,7 @@ def get_command_view(
queued_setup_command_ids=OrderedSet(queued_setup_command_ids),
run_error=run_error,
finish_error=finish_error,
failed_command=failed_command,
all_command_ids=all_command_ids,
commands_by_id=commands_by_id,
run_started_at=run_started_at,
Expand Down

0 comments on commit 690f5aa

Please sign in to comment.