refactor: replace try-except blocks with contextlib.suppress for cleaner error handling across multiple files

This commit is contained in:
Jack Lu
2026-05-01 19:30:11 +08:00
committed by Xubin Ren
parent 1c24f10236
commit d9800ecdd2
27 changed files with 98 additions and 195 deletions
+2 -4
View File
@@ -7,7 +7,7 @@ import dataclasses
import json
import os
import time
from contextlib import AsyncExitStack, nullcontext
from contextlib import AsyncExitStack, nullcontext, suppress
from pathlib import Path
from typing import TYPE_CHECKING, Any, Awaitable, Callable
@@ -492,10 +492,8 @@ class AgentLoop:
tasks = self._active_tasks.pop(key, [])
cancelled = sum(1 for t in tasks if not t.done() and t.cancel())
for t in tasks:
try:
with suppress(asyncio.CancelledError, Exception):
await t
except (asyncio.CancelledError, Exception):
pass
sub_cancelled = await self.subagents.cancel_by_session(key)
return cancelled + sub_cancelled