Skip to content

Commit 7e4dfca

Browse files
committed
Remove unnecessary try-except for CancelledError in _check_errors
The task.cancelled() check on line 281 already ensures that CancelledError will never be raised when calling task.exception(). The try-except block was redundant and added unnecessary complexity. Thanks to reviewer comment for catching this.
1 parent a52d0c9 commit 7e4dfca

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/agents/voice/result.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,14 @@ async def _cleanup_tasks(self):
275275
def _check_errors(self):
276276
"""Check for exceptions in completed tasks.
277277
278-
Note: CancelledError is not checked as it's expected during cleanup.
278+
Note: task.cancelled() check ensures CancelledError is never raised.
279279
"""
280280
for task in self._tasks:
281281
if task.done() and not task.cancelled():
282-
try:
283-
exc = task.exception()
284-
if exc:
285-
self._stored_exception = exc
286-
break
287-
except asyncio.CancelledError:
288-
# Task was cancelled, skip it
289-
pass
282+
exc = task.exception()
283+
if exc:
284+
self._stored_exception = exc
285+
break
290286

291287
async def stream(self) -> AsyncIterator[VoiceStreamEvent]:
292288
"""Stream the events and audio data as they're generated."""

0 commit comments

Comments
 (0)