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

refactor(api): hardware controller use error codes #13318

Merged
merged 5 commits into from
Sep 29, 2023

Conversation

ahiuchingau
Copy link
Contributor

@ahiuchingau ahiuchingau commented Aug 16, 2023

Overview

We are now using the error codes in the hardware controller api. Let me know if i forgot anything!

@codecov
Copy link

codecov bot commented Aug 16, 2023

Codecov Report

Merging #13318 (82a66c2) into edge (28deba6) will decrease coverage by 0.19%.
Report is 12 commits behind head on edge.
The diff coverage is 33.33%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             edge   #13318      +/-   ##
==========================================
- Coverage   71.26%   71.08%   -0.19%     
==========================================
  Files        1588     1593       +5     
  Lines       52824    53026     +202     
  Branches     3481     3548      +67     
==========================================
+ Hits        37646    37693      +47     
- Misses      14627    14782     +155     
  Partials      551      551              
Flag Coverage Δ
app 44.12% <ø> (+0.06%) ⬆️
g-code-testing 96.44% <ø> (ø)
hardware-testing ∅ <ø> (∅)
notify-server 89.13% <ø> (ø)
protocol-designer 45.40% <ø> (-0.62%) ⬇️
shared-data 73.96% <33.33%> (-0.30%) ⬇️
step-generation 86.79% <ø> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
api/src/opentrons/hardware_control/__init__.py 100.00% <ø> (ø)
api/src/opentrons/hardware_control/api.py 82.42% <ø> (-0.29%) ⬇️
.../opentrons/hardware_control/backends/controller.py 73.05% <ø> (+1.70%) ⬆️
...entrons/hardware_control/backends/ot3controller.py 68.04% <ø> (-0.38%) ⬇️
...c/opentrons/hardware_control/backends/simulator.py 88.37% <ø> (-0.27%) ⬇️
...rc/opentrons/hardware_control/execution_manager.py 90.54% <ø> (ø)
api/src/opentrons/hardware_control/ot3api.py 79.53% <ø> (-0.06%) ⬇️
...ns/hardware_control/protocols/motion_controller.py 51.72% <ø> (-1.61%) ⬇️
api/src/opentrons/hardware_control/util.py 97.05% <ø> (-0.24%) ⬇️
...i/src/opentrons/protocol_api/instrument_context.py 87.81% <ø> (-0.12%) ⬇️
... and 6 more

... and 41 files with indirect coverage changes

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline feedback!


@wraps(func)
async def wrapper(self: Any, *args: Any, **kwargs: Any) -> Any:
if self.update_required and self.initialized:
raise FirmwareUpdateRequired()
raise FirmwareUpdateRequiredError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea with these errors is that you can pack details in them, and we should generally take advantage of that. so here for instance, you could put in the details argument a dict containing like

  • func.__name__
  • update_required and initialized
  • maybe even poke into self.subsystems and figuring out which subsystems need the update

def __init__(self, message: str):
self.message = message
super().__init__()
super().__init__(message=message)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also pass the details in and store them in details

api/src/opentrons/hardware_control/ot3api.py Outdated Show resolved Hide resolved
api/src/opentrons/hardware_control/ot3api.py Outdated Show resolved Hide resolved
api/src/opentrons/hardware_control/ot3api.py Show resolved Hide resolved
api/src/opentrons/hardware_control/ot3api.py Show resolved Hide resolved
api/src/opentrons/hardware_control/ot3api.py Outdated Show resolved Hide resolved
@ahiuchingau ahiuchingau changed the base branch from edge to chore_release-7.0.0 September 18, 2023 20:09
@ahiuchingau ahiuchingau marked this pull request as ready for review September 19, 2023 18:21
@ahiuchingau ahiuchingau requested review from a team as code owners September 19, 2023 18:21
HardwareMustHomeError -> PositionUnknownError
GripperNotAttachedError -> GripperNotPresentError
AxisNotPresentError -> InvalidActuator
FirmwareUpdateRequired -> FirmwareUpdateRequiredError
FirmwareUpdateFailed -> FirmwareUpdateFailedError
InvalidMove -> InvalidCriticalPoint
UpdateOngoingError as part of RobotInUseError
NotSupportedByHardware -> UnsupportedHardwareCommand
NoTipAttachedError -> UnexpectedTipRemovalError
TipAttachedError -> UnexpectedTipAttachError
add detail for error msgs in ot3api.py
gripper errors
fix tests
@ahiuchingau ahiuchingau requested a review from a team as a code owner September 20, 2023 18:19
@ahiuchingau ahiuchingau requested review from brenthagen and removed request for a team September 20, 2023 18:19
@ahiuchingau ahiuchingau changed the base branch from chore_release-7.0.0 to edge September 20, 2023 18:19
Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple nitpicks but looking good!

@@ -107,7 +107,7 @@ async def get_position(
critical_point=pipette_location.critical_point,
fail_on_not_homed=fail_on_not_homed,
)
except HardwareMustHomeError as e:
except PositionUnknownError as e:
raise MustHomeError(str(e)) from e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should link the lower level error with wraps=[e]

@@ -167,7 +167,7 @@ async def move_relative(
critical_point=critical_point,
fail_on_not_homed=True,
)
except HardwareMustHomeError as e:
except PositionUnknownError as e:
raise MustHomeError(str(e)) from e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should link the error with wraps=[e]

f"Motor positions for {str(mount)} are missing; must first home motors."
raise PositionUnknownError(
message=f"Motor positions for {str(mount)} are missing; must first home motors.",
detail={"mount": str(mount)},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we put the exact missing axis positions in the mount?

raise MustHomeError(
f"Current position of {str(mount)} pipette is unknown, please home."
raise PositionUnknownError(
message=f"Current position of {str(mount)} pipette is unknown, please home."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe put in the details whether the problem is that the axis isn't homed or that position hasn't been pulled yet

raise NotSupportedByHardware(
f"At least one axis in {axes} is not supported on the OT2."
raise UnsupportedHardwareCommand(
message=f"At least one axis in {axes} is not supported on the OT2."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe worth putting in which axis it is, at least in the details

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@ahiuchingau ahiuchingau merged commit 8569e32 into edge Sep 29, 2023
43 of 47 checks passed
@ahiuchingau ahiuchingau deleted the api_use-error-codes branch September 29, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants