Skip to content

Commit

Permalink
Handle missing 'op_name' key in response
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJKoopman committed Oct 14, 2024
1 parent c7a57b1 commit 2568a7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/sorunlib/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def check_response(client, response):
initial request or after completion) or the response has timed out.
"""
op = response.session['op_name']
try:
op = response.session['op_name']
except KeyError:
error = f"Unable to parse response from {client}:\n{str(response)}"
raise RuntimeError(error)
instance = client.instance_id

_check_error(client, response)
Expand Down
9 changes: 8 additions & 1 deletion tests/test__internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ def __init__(self):
self.test_op = MagicMock()


# Attempt to recreate https://github.com/simonsobs/sorunlib/issues/174
malformed_session = create_session('test', success=False)
malformed_session.pop('op_name')

invalid_responses = [(MockClient(), OCSReply(ocs.TIMEOUT,
'msg',
create_session('test', success=True))),
(MockClient(), OCSReply(ocs.ERROR,
'msg',
create_session('test', success=False)))]
create_session('test', success=False))),
(MockClient(), OCSReply(ocs.ERROR,
'msg',
malformed_session))]

valid_responses = [
(MockClient(), OCSReply(ocs.OK, 'msg', create_session('test', success=True)))]
Expand Down

0 comments on commit 2568a7e

Please sign in to comment.