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): Report Python protocol line numbers for errors from Protocol Engine #13537

Merged
merged 10 commits into from
Sep 13, 2023

Conversation

SyntaxColoring
Copy link
Contributor

@SyntaxColoring SyntaxColoring commented Sep 12, 2023

Overview

Fixes RSS-317.

Test Plan

  • E-stop a physical run on a Flex and make sure the desktop app and ODD respond correctly.
  • Import the protocol from RSS-317 and make sure it shows a line number now.

Changelog

  • Bug fix: When an exception bubbles out of the Python protocol exec(), do not handle it specially just because that exception passed through Protocol Engine. Handle it like any other exception. This lets us attach the protocol line number to it.

    We were handling it specially before because, I guess, we wanted it to collude with this isinstance check up in ProtocolEngine.finish(). Apparently this was unnecessary, because the ExceptionInProtocolError that we would wrap it with passes the isinstance check just the same.

  • Add some analysis integration tests that make sure the line number shows up.

  • Resolve some type-checking exclusions in opentrons.protocols.execute.

Review requests

  • Do the comments make sense?
  • Do we have a reasonable way of inducing E-stop errors in CI tests?

Risk assessment

Probably medium-high. The special E-stop handling is hard to reason about and unit-test because it works by several far-away places colluding with each other.

@SyntaxColoring SyntaxColoring changed the base branch from edge to chore_release-7.0.0 September 12, 2023 21:18
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No substantive changes in here, just adding type annotations and rearranging things for readability.

@codecov
Copy link

codecov bot commented Sep 12, 2023

Codecov Report

Merging #13537 (61ed31a) into chore_release-7.0.0 (443e88c) will decrease coverage by 0.01%.
Report is 21 commits behind head on chore_release-7.0.0.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@                   Coverage Diff                   @@
##           chore_release-7.0.0   #13537      +/-   ##
=======================================================
- Coverage                71.30%   71.30%   -0.01%     
=======================================================
  Files                     2418     2418              
  Lines                    68007    68002       -5     
  Branches                  7896     7896              
=======================================================
- Hits                     48492    48487       -5     
  Misses                   17668    17668              
  Partials                  1847     1847              
Flag Coverage Δ
g-code-testing 96.44% <ø> (ø)

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

Files Changed Coverage Δ
...i/src/opentrons/protocol_engine/protocol_engine.py 100.00% <ø> (ø)
api/src/opentrons/protocols/execution/errors.py 100.00% <ø> (ø)
api/src/opentrons/protocols/execution/execute.py 90.90% <ø> (-0.40%) ⬇️
...rc/opentrons/protocols/execution/execute_python.py 87.23% <ø> (ø)
.../opentrons/protocols/execution/json_dispatchers.py 90.90% <ø> (-0.76%) ⬇️

@SyntaxColoring SyntaxColoring marked this pull request as ready for review September 12, 2023 21:42
@SyntaxColoring SyntaxColoring requested a review from a team as a code owner September 12, 2023 21:42
Comment on lines 350 to 351
# TODO(mm, 2023-09-12): Do we need to scan the exception tree like this? Instead, can we
# directly inspect the E-stop state through self._hardware_api.get_estop_state()?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TamarZanzouri @sfoster1 Thoughts on this # TODO?

Copy link
Member

Choose a reason for hiding this comment

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

We need to scan the exception tree because someone in theory could have released the estop really fast after pressing it and the physical estop state would not be the same as the one that caused the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mm, yeah, okay.

Would that be likely in practice? I think someone would have to physically release the E-stop button and PUT /robot/control/acknowledgeEstopDisengage before the exception finishes its journey from the hardware controller to ProtocolEngine.finish(). (I don't think that means it doesn't matter—just developing a mental model.)

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 to me! It makes sense and I agree with it. However, I think the todo is wrong - see the inline comment.

Copy link
Contributor

@TamarZanzouri TamarZanzouri left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@SyntaxColoring SyntaxColoring merged commit 357f76a into chore_release-7.0.0 Sep 13, 2023
@SyntaxColoring SyntaxColoring deleted the pe_error_message_line_number branch September 13, 2023 15:12
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.

3 participants