-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f307641
commit 73cc326
Showing
5 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
api/src/opentrons/protocol_engine/error_recovery_policy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import enum | ||
from typing import Protocol | ||
|
||
from opentrons_shared_data.errors import EnumeratedError, ErrorCodes | ||
|
||
from opentrons.config import feature_flags as ff | ||
|
||
|
||
class ErrorRecoveryType(enum.Enum): | ||
"""Ways to handle a command failure.""" | ||
|
||
FAIL_RUN = enum.auto() | ||
"""Permanently fail the entire run.""" | ||
|
||
WAIT_FOR_RECOVERY = enum.auto() | ||
"""Stop and wait for the error to be recovered from manually.""" | ||
|
||
CONTINUE = enum.auto() | ||
"""Continue with the run, as if the command never failed.""" | ||
|
||
|
||
class ErrorRecoveryPolicy(Protocol): | ||
@staticmethod | ||
def __call__(exception: Exception) -> ErrorRecoveryType: | ||
... | ||
|
||
|
||
def error_recovery_by_ff(exception: Exception) -> ErrorRecoveryType: | ||
"""Use API feature flags to decide how to handle an error. | ||
This is just for development. This should be replaced by a proper config | ||
system exposed through robot-server's HTTP API. | ||
""" | ||
if _is_recoverable(exception) and ff.enable_error_recovery_experiments(): | ||
return ErrorRecoveryType.WAIT_FOR_RECOVERY | ||
else: | ||
return ErrorRecoveryType.FAIL_RUN | ||
|
||
|
||
def _is_recoverable(exception: Exception) -> bool: | ||
if isinstance(exception, EnumeratedError): | ||
return exception.code in { | ||
ErrorCodes.TIP_PICKUP_FAILED, | ||
ErrorCodes.PIPETTE_OVERPRESSURE, | ||
} | ||
else: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters