Skip to content

Commit

Permalink
refactor get command errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Nov 5, 2024
1 parent e423f37 commit e29d95f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions api/src/opentrons/protocol_engine/state/command_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class CommandHistory:
_all_command_ids: List[str]
"""All command IDs, in insertion order."""

_all_failed_command_ids: List[str]
"""All failed command IDs, in insertion order."""

_all_command_ids_but_fixit_command_ids: List[str]
"""All command IDs besides fixit command intents, in insertion order."""

Expand Down Expand Up @@ -101,6 +104,13 @@ def get_all_commands(self) -> List[Command]:
for command_id in self._all_command_ids
]

def get_all_failed_commands(self) -> List[Command]:
"""Get all failed commands."""
return [
self._commands_by_id[command_id].command
for command_id in self._all_failed_command_ids
]

def get_filtered_command_ids(self, include_fixit_commands: bool) -> List[str]:
"""Get all fixit command IDs."""
if include_fixit_commands:
Expand Down Expand Up @@ -251,6 +261,10 @@ def _add(self, command_id: str, command_entry: CommandEntry) -> None:
self._all_command_ids_but_fixit_command_ids.append(command_id)
self._commands_by_id[command_id] = command_entry

def append_failed_command_id(self, command_id: str) -> None:
"""Create or update a failed command id."""
self._all_failed_command_ids.append(command_id)

def _add_to_queue(self, command_id: str) -> None:
"""Add new ID to the queued."""
self._queued_command_ids.add(command_id)
Expand Down
5 changes: 3 additions & 2 deletions api/src/opentrons/protocol_engine/state/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def _handle_fail_command_action(self, action: FailCommandAction) -> None:
notes=action.notes,
)
self._state.failed_command = self._state.command_history.get(action.command_id)
self._state.command_history.append_failed_command_id(action.command_id)

if (
prev_entry.command.intent in (CommandIntent.PROTOCOL, None)
Expand Down Expand Up @@ -701,10 +702,10 @@ def get_error(self) -> Optional[ErrorOccurrence]:

def get_all_errors(self) -> List[ErrorOccurrence]:
"""Get the run's full error list, if there was none, returns an empty list."""
command_errors = self._state.command_history.get_all_commands()
failed_commands = self._state.command_history.get_all_failed_commands()
return [
command_error.error
for command_error in command_errors
for command_error in failed_commands
if command_error.error is not None
]

Expand Down

0 comments on commit e29d95f

Please sign in to comment.