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): inherit protocol api errors from enumerated errors #15516

Merged
merged 8 commits into from
Jul 9, 2024

Conversation

pmoegenburg
Copy link
Member

@pmoegenburg pmoegenburg commented Jun 25, 2024

Overview

This PR changes Protocol API APIVersionError to inherit from enumerated error IncorrectAPIVersion and Protocol API UnsupportedAPIError to inherit from enumerated error APIRemoved.

Test Plan

Changelog

Review requests

Risk assessment

@pmoegenburg pmoegenburg self-assigned this Jun 25, 2024
@pmoegenburg pmoegenburg requested a review from a team as a code owner June 25, 2024 19:29
Copy link
Contributor

A PR has been opened to address analyses snapshot changes. Please review the changes here: #15518

Comment on lines -48 to +52
class UnsupportedAPIError(Exception):
class UnsupportedAPIError(APIRemoved):
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this exception is currently unused, so it doesn't really matter, but note that "API removed" is not the only thing that could be meant by "a protocol attempts to use an unsupported API." It could also mean that the protocol attempts to use an API that's too new, like if you tried to use "apiLevel": "2.19" on robot software v5.0. (We're currently just raising ValueError for that, but we probably shouldn't be.)

I wonder if we want just a generic code and exception for any protocol API version error. I'm not sure it's worth having 3 separate things for "too old," "too new," and "supported but invalid."

Copy link
Contributor

Choose a reason for hiding this comment

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

Three is probably too many, yes. Two is probably good, breaking down into:

  • Something is wrong with the combination of your code and API version.
  • Your code used to be good but isn't anymore and furthermore that feature is never coming back ever ever so don't get your hopes up.

Copy link
Contributor

@SyntaxColoring SyntaxColoring Jun 27, 2024

Choose a reason for hiding this comment

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

But I think I'm trying to say that that specific breakdown of 2 is not sufficient to cover the case where your code is good, you just need to update your robot. That breakdown is covering problems like protocol_apilevel < MIN_SUPPORTED_VERSION and not feature_available_in(protocol_apilevel), but is not covering the problem of protocol_apilevel > MAX_SUPPORTED_VERSION.

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 good but you'll have to change the way you create the exception - take a look at the exception definition in shared-data for how to do that. You'll also have to add the code to the underlying json file in shared-data/errors.

Copy link
Contributor

A PR has been opened to address analyses snapshot changes. Please review the changes here: #15518

@pmoegenburg pmoegenburg requested a review from a team as a code owner June 27, 2024 12:55
Copy link
Contributor

A PR has been opened to address analyses snapshot changes. Please review the changes here: #15518

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 good once you clean up dev comments

checked_detail["identifier"] = api_element
checked_detail["until_version"] = until_version
checked_detail["current_version"] = current_version
# make this cleaner?!
Copy link
Member

Choose a reason for hiding this comment

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

Remove or make a proper todo comment (I think the code is fine as is though)

f"Deleting deck elements is not supported with apiLevel {self._api_version}."
f" Try increasing your apiLevel to {APIVersion(2, 15)}."
api_element="Deleting deck elements",
until_version="2.15",
Copy link
Contributor

@ecormany ecormany Jul 2, 2024

Choose a reason for hiding this comment

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

Wait, was del protocol.deck[1] actually broken in 2.14? I don't think we ever documented that.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, definitely

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, all we have is this:

Changed in version 2.14: Includes the Thermocycler in all of the slots it occupies.

Changed in version 2.15: del sets the corresponding labware’s location to OFF_DECK.

We could update the versionchanged notice…or not.

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.

Nice work!

@pmoegenburg pmoegenburg merged commit 0e005dd into edge Jul 9, 2024
53 checks passed
syao1226 pushed a commit that referenced this pull request Jul 10, 2024
<!--
Thanks for taking the time to open a pull request! Please make sure
you've read the "Opening Pull Requests" section of our Contributing
Guide:


https://github.com/Opentrons/opentrons/blob/edge/CONTRIBUTING.md#opening-pull-requests

To ensure your code is reviewed quickly and thoroughly, please fill out
the sections below to the best of your ability!
-->

# Overview

<!--
Use this section to describe your pull-request at a high level. If the
PR addresses any open issues, please tag the issues here.
-->

This PR changes Protocol API APIVersionError to inherit from enumerated
error IncorrectAPIVersion and Protocol API UnsupportedAPIError to
inherit from enumerated error APIRemoved.

# Test Plan

<!--
Use this section to describe the steps that you took to test your Pull
Request.
If you did not perform any testing provide justification why.

OT-3 Developers: You should default to testing on actual physical
hardware.
Once again, if you did not perform testing against hardware, justify
why.

Note: It can be helpful to write a test plan before doing development

Example Test Plan (HTTP API Change)

- Verified that new optional argument `dance-party` causes the robot to
flash its lights, move the pipettes,
then home.
- Verified that when you omit the `dance-party` option the robot homes
normally
- Added protocol that uses `dance-party` argument to G-Code Testing
Suite
- Ran protocol that did not use `dance-party` argument and everything
was successful
- Added unit tests to validate that changes to pydantic model are
correct

-->

# Changelog

<!--
List out the changes to the code in this PR. Please try your best to
categorize your changes and describe what has changed and why.

Example changelog:
- Fixed app crash when trying to calibrate an illegal pipette
- Added state to API to track pipette usage
- Updated API docs to mention only two pipettes are supported

IMPORTANT: MAKE SURE ANY BREAKING CHANGES ARE PROPERLY COMMUNICATED
-->

# Review requests

<!--
Describe any requests for your reviewers here.
-->

# Risk assessment

<!--
Carefully go over your pull request and look at the other parts of the
codebase it may affect. Look for the possibility, even if you think it's
small, that your change may affect some other part of the system - for
instance, changing return tip behavior in protocol may also change the
behavior of labware calibration.

Identify the other parts of the system your codebase may affect, so that
in addition to your own review and testing, other people who may not
have the system internalized as much as you can focus their attention
and testing there.
-->
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.

4 participants