Skip to content

Commit 66ddd35

Browse files
committed
initial implementation
1 parent 7590453 commit 66ddd35

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

api/src/opentrons/protocols/api_support/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
from opentrons.hardware_control.types import Axis
2323
from opentrons.hardware_control.util import ot2_axis_to_string
2424
from opentrons_shared_data.robot.dev_types import RobotType
25+
from opentrons_shared_data.errors.exceptions import (
26+
APIRemoved,
27+
IncorrectAPIVersion,
28+
)
2529

2630
if TYPE_CHECKING:
2731
from opentrons.protocol_api.labware import Well, Labware
@@ -37,15 +41,15 @@
3741
MODULE_LOG = logging.getLogger(__name__)
3842

3943

40-
class APIVersionError(Exception):
44+
class APIVersionError(IncorrectAPIVersion):
4145
"""
4246
Error raised when a protocol attempts to access behavior not implemented
4347
"""
4448

4549
pass
4650

4751

48-
class UnsupportedAPIError(Exception):
52+
class UnsupportedAPIError(APIRemoved):
4953
"""Error raised when a protocol attempts to use unsupported API."""
5054

5155

shared-data/python/opentrons_shared_data/errors/codes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class ErrorCodes(Enum):
9292
INVALID_STORED_DATA = _code_from_dict_entry("4008")
9393
MISSING_CONFIGURATION_DATA = _code_from_dict_entry("4009")
9494
RUNTIME_PARAMETER_VALUE_REQUIRED = _code_from_dict_entry("4010")
95+
INCORRECT_API_VERSION = _code_from_dict_entry("4011")
9596

9697
@classmethod
9798
@lru_cache(25)

shared-data/python/opentrons_shared_data/errors/exceptions.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,30 @@ def __init__(
921921
)
922922

923923

924+
class IncorrectAPIVersion(GeneralError):
925+
"""An error indicating that a command was issued that is not supported by the API version in use."""
926+
927+
def __init(
928+
self,
929+
api_element: str,
930+
until_version: str,
931+
message: Optional[str] = None,
932+
detail: Optional[Dict[str, str]] = None,
933+
wrapping: Optional[Sequence[EnumeratedError]] = None,
934+
) -> None:
935+
"""Build an IncorrectAPIVersion error."""
936+
checked_detail: Dict[str, Any] = detail or {}
937+
checked_detail["identifier"] = api_element
938+
checked_detail["until_version"] = until_version
939+
checked_message = (
940+
message
941+
or f"{api_element} is not available until version {until_version}."
942+
)
943+
super().__init__(
944+
ErrorCodes.INCORRECT_API_VERSION, checked_message, checked_detail, wrapping
945+
)
946+
947+
924948
class CommandPreconditionViolated(GeneralError):
925949
"""An error indicating that a command was issued in a robot state incompatible with it."""
926950

0 commit comments

Comments
 (0)