Skip to content

Commit

Permalink
execute_python: fix exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoster1 committed Aug 7, 2024
1 parent a9ccfd3 commit 697004e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions api/src/opentrons/protocols/execution/execute_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ def _add_parameters_func_ok(add_parameters_func: Any) -> None:
raise SyntaxError("Function 'add_parameters' must take exactly one argument.")


def _find_protocol_error(tb: TracebackType, proto_name: str) -> traceback.FrameSummary:
def _find_protocol_error(
tb: TracebackType | None, proto_name: str
) -> traceback.FrameSummary:
"""Return the FrameInfo for the lowest frame in the traceback from the
protocol.
"""
if tb is None:
raise KeyError
tb_info = traceback.extract_tb(tb)
for frame in reversed(tb_info):
if frame.filename == proto_name:
Expand All @@ -59,8 +63,6 @@ def _find_protocol_error(tb: TracebackType, proto_name: str) -> traceback.FrameS

def _raise_pretty_protocol_error(exception: Exception, filename: str) -> None:
_, _, tb = sys.exc_info()
if tb is None:
raise Exception
try:
frame = _find_protocol_error(tb, filename)
except KeyError:
Expand Down

0 comments on commit 697004e

Please sign in to comment.