Skip to content

Commit

Permalink
raise protocol error from ValueError
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Jun 13, 2023
1 parent d07c45b commit 143da37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions ahk/_async/transport.py
Expand Up @@ -720,7 +720,13 @@ async def _send_nonblocking(
content_buffer = BytesIO()
content_buffer.write(tom)
content_buffer.write(num_lines)
for _ in range(int(num_lines) + 1):
try:
lines_to_read = int(num_lines) + 1
except ValueError as e:
raise AHKProtocolError(
'Unexpected data received. This is usually the result of an unhandled error in the AHK process.'
) from e
for _ in range(lines_to_read):
part = await proc.readline()
content_buffer.write(part)
content = content_buffer.getvalue()[:-1]
Expand Down Expand Up @@ -767,10 +773,10 @@ async def send(
content_buffer.write(num_lines)
try:
lines_to_read = int(num_lines) + 1
except ValueError:
except ValueError as e:
raise AHKProtocolError(
'Unexpected data received. This is usually the result of an unhandled error in the AHK process.'
)
) from e
for _ in range(lines_to_read):
part = await self._proc.readline()
content_buffer.write(part)
Expand Down
12 changes: 9 additions & 3 deletions ahk/_sync/transport.py
Expand Up @@ -694,7 +694,13 @@ def _send_nonblocking(
content_buffer = BytesIO()
content_buffer.write(tom)
content_buffer.write(num_lines)
for _ in range(int(num_lines) + 1):
try:
lines_to_read = int(num_lines) + 1
except ValueError as e:
raise AHKProtocolError(
'Unexpected data received. This is usually the result of an unhandled error in the AHK process.'
) from e
for _ in range(lines_to_read):
part = proc.readline()
content_buffer.write(part)
content = content_buffer.getvalue()[:-1]
Expand Down Expand Up @@ -733,10 +739,10 @@ def send(
content_buffer.write(num_lines)
try:
lines_to_read = int(num_lines) + 1
except ValueError:
except ValueError as e:
raise AHKProtocolError(
'Unexpected data received. This is usually the result of an unhandled error in the AHK process.'
)
) from e
for _ in range(lines_to_read):
part = self._proc.readline()
content_buffer.write(part)
Expand Down

0 comments on commit 143da37

Please sign in to comment.