Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): restore empty error blocks on cancelled runs #15215

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions api/src/opentrons/protocol_engine/state/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,21 @@ def handle_action(self, action: Action) -> None: # noqa: C901
else:
self._state.run_result = RunResult.STOPPED

if not self._state.run_error and action.error_details:
self._state.run_error = self._map_run_exception_to_error_occurrence(
action.error_details.error_id,
action.error_details.created_at,
action.error_details.error,
)
if not self._state.run_error and action.error_details:
self._state.run_error = self._map_run_exception_to_error_occurrence(
action.error_details.error_id,
action.error_details.created_at,
action.error_details.error,
)
else:
# HACK(sf): There needs to be a better way to set
# an estop error than this else clause
if self._state.stopped_by_estop and action.error_details:
self._state.run_error = self._map_run_exception_to_error_occurrence(
action.error_details.error_id,
action.error_details.created_at,
action.error_details.error,
)

elif isinstance(action, HardwareStoppedAction):
self._state.queue_status = QueueStatus.PAUSED
Expand Down
30 changes: 30 additions & 0 deletions api/tests/opentrons/protocol_engine/state/test_command_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,33 @@ def test_final_state_after_estop() -> None:

assert subject_view.get_status() == EngineStatus.FAILED
assert subject_view.get_error() == expected_error_occurrence


def test_final_state_after_stop() -> None:
"""Test the final state of the run after it's stopped."""
subject = CommandStore(config=_make_config(), is_door_open=False)
subject_view = CommandView(subject.state)

subject.handle_action(actions.StopAction())
subject.handle_action(
actions.FinishAction(
error_details=actions.FinishErrorDetails(
error=RuntimeError(
"uh oh I was a command and then I got cancelled because someone"
" stopped the run, and now I'm raising this exception because"
" of that. Woe is me"
),
error_id="error-id",
created_at=datetime.now(),
)
)
)
subject.handle_action(
actions.HardwareStoppedAction(
completed_at=sentinel.hardware_stopped_action_completed_at,
finish_error_details=None,
)
)

assert subject_view.get_status() == EngineStatus.STOPPED
assert subject_view.get_error() is None
Loading