Skip to content

Commit 7d6e33f

Browse files
committed
refactor: deduplicate warning log in oversized message handler
Merge the two except branches (LimitOverrunError, ValueError) into one, using isinstance() to gate the re-raise check for unrelated ValueErrors. Eliminates the duplicated 5-line logging.warning() call.
1 parent 2b834fb commit 7d6e33f

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/acp/connection.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,16 @@ async def _receive_loop(self) -> None:
150150
while True:
151151
try:
152152
line = await self._reader.readline()
153-
except asyncio.LimitOverrunError as exc:
153+
except (asyncio.LimitOverrunError, ValueError) as exc:
154154
# The message exceeded the StreamReader's buffer limit.
155-
# On Python < 3.12 the raw LimitOverrunError propagates.
156-
logging.warning(
157-
"Skipped oversized JSON-RPC message that exceeded the "
158-
"StreamReader buffer limit: %s. The connection will "
159-
"continue processing subsequent messages. Consider "
160-
"increasing the buffer limit via stdio_buffer_limit_bytes "
161-
"if large messages are expected.",
162-
exc,
163-
)
164-
continue
165-
except ValueError as exc:
166155
# Python 3.12+ wraps LimitOverrunError as ValueError inside
167-
# readline(), and cleans up the internal buffer. Re-raise
168-
# if this ValueError is NOT the limit-overrun wrapper so we
169-
# don't accidentally mask unrelated errors.
170-
exc_msg = str(exc).lower()
171-
if "limit" not in exc_msg and "chunk" not in exc_msg:
172-
raise
156+
# readline(); older versions raise LimitOverrunError directly.
157+
# Re-raise ValueErrors that are NOT the limit-overrun wrapper
158+
# so we don't accidentally mask unrelated errors.
159+
if isinstance(exc, ValueError):
160+
exc_msg = str(exc).lower()
161+
if "limit" not in exc_msg and "chunk" not in exc_msg:
162+
raise
173163
logging.warning(
174164
"Skipped oversized JSON-RPC message that exceeded the "
175165
"StreamReader buffer limit: %s. The connection will "

0 commit comments

Comments
 (0)