Skip to content

Commit

Permalink
Add error recovery debug notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring committed Oct 25, 2024
1 parent 2a4d086 commit 042baec
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
25 changes: 15 additions & 10 deletions api/src/opentrons/protocol_engine/execution/command_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)

from opentrons.protocol_engine.commands.command import SuccessData
from opentrons.protocol_engine.notes import make_error_recovery_debug_note

from ..state.state import StateStore
from ..resources import ModelUtils, FileProvider
Expand Down Expand Up @@ -161,6 +162,12 @@ async def execute(self, command_id: str) -> None:
elif not isinstance(error, EnumeratedError):
error = PythonException(error)

error_recovery_type = error_recovery_policy(
self._state_store.config,
running_command,
None,
)
note_tracker(make_error_recovery_debug_note(error_recovery_type))
self._action_dispatcher.dispatch(
FailCommandAction(
error=error,
Expand All @@ -169,11 +176,7 @@ async def execute(self, command_id: str) -> None:
error_id=self._model_utils.generate_id(),
failed_at=self._model_utils.get_timestamp(),
notes=note_tracker.get_notes(),
type=error_recovery_policy(
self._state_store.config,
running_command,
None,
),
type=error_recovery_type,
)
)

Expand All @@ -195,6 +198,12 @@ async def execute(self, command_id: str) -> None:
)
else:
# The command encountered a defined error.
error_recovery_type = error_recovery_policy(
self._state_store.config,
running_command,
result,
)
note_tracker(make_error_recovery_debug_note(error_recovery_type))
self._action_dispatcher.dispatch(
FailCommandAction(
error=result,
Expand All @@ -203,10 +212,6 @@ async def execute(self, command_id: str) -> None:
error_id=result.public.id,
failed_at=result.public.createdAt,
notes=note_tracker.get_notes(),
type=error_recovery_policy(
self._state_store.config,
running_command,
result,
),
type=error_recovery_type,
)
)
16 changes: 14 additions & 2 deletions api/src/opentrons/protocol_engine/notes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
"""Protocol engine notes module."""

from .notes import NoteKind, CommandNote, CommandNoteAdder, CommandNoteTracker
from .notes import (
NoteKind,
CommandNote,
CommandNoteAdder,
CommandNoteTracker,
make_error_recovery_debug_note,
)

__all__ = ["NoteKind", "CommandNote", "CommandNoteAdder", "CommandNoteTracker"]
__all__ = [
"NoteKind",
"CommandNote",
"CommandNoteAdder",
"CommandNoteTracker",
"make_error_recovery_debug_note",
]
19 changes: 18 additions & 1 deletion api/src/opentrons/protocol_engine/notes/notes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Definitions of data and interface shapes for notes."""
from typing import Union, Literal, Protocol, List
from typing import Union, Literal, Protocol, List, TYPE_CHECKING
from pydantic import BaseModel, Field

if TYPE_CHECKING:
from opentrons.protocol_engine.error_recovery_policy import ErrorRecoveryType

NoteKind = Union[Literal["warning", "information"], str]


Expand All @@ -26,6 +29,20 @@ class CommandNote(BaseModel):
)


def make_error_recovery_debug_note(type: "ErrorRecoveryType") -> CommandNote:
"""Return a note for debugging error recovery.
This is intended to be read by developers and support people, not computers.
"""
message = f"Handling this command failure with {type.name}."
return CommandNote.construct(
noteKind="debugErrorRecovery",
shortMessage=message,
longMessage=message,
source="execution",
)


class CommandNoteAdder(Protocol):
"""The shape of a function that something can use to add a command note."""

Expand Down

0 comments on commit 042baec

Please sign in to comment.