Skip to content

Commit 5fdaa62

Browse files
author
Gabriele Panico
committed
feat: add detailed exception formatting for improved error logging in get_all_filtered_tools
1 parent 6a207a8 commit 5fdaa62

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

tilellm/controller/controller_utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,24 @@ async def get_filtered_tools(
13501350
return [t for t in all_tools if t.name in enabled_names]
13511351

13521352

1353+
def _format_exception_details(exc: BaseException, *, indent: str = "") -> str:
1354+
"""Format exception text for logs, unwrapping ExceptionGroup / TaskGroup wrappers."""
1355+
if isinstance(exc, BaseExceptionGroup):
1356+
lines = [f"{indent}{type(exc).__name__}: {exc}"]
1357+
for i, sub in enumerate(exc.exceptions):
1358+
lines.append(f"{indent} sub-exception [{i}]:")
1359+
lines.append(_format_exception_details(sub, indent=indent + " "))
1360+
return "\n".join(lines)
1361+
lines = [f"{indent}{type(exc).__name__}: {exc}"]
1362+
if exc.__cause__:
1363+
lines.append(f"{indent} cause:")
1364+
lines.append(_format_exception_details(exc.__cause__, indent=indent + " "))
1365+
elif exc.__context__ and not exc.__suppress_context__:
1366+
lines.append(f"{indent} context:")
1367+
lines.append(_format_exception_details(exc.__context__, indent=indent + " "))
1368+
return "\n".join(lines)
1369+
1370+
13531371
async def get_all_filtered_tools(mcp_client, servers_config: Dict[str, ServerConfig]) -> List[BaseTool]:
13541372
"""
13551373
Recupera e filtra i tool server per server prima di unirli.
@@ -1378,7 +1396,12 @@ async def get_all_filtered_tools(mcp_client, servers_config: Dict[str, ServerCon
13781396

13791397
except Exception as e:
13801398
# Gestione errore se un server specifico non risponde o non esiste
1381-
print(f"Errore nel recupero tool per il server {server_name}: {e}")
1399+
logger.error(
1400+
"Errore nel recupero tool per il server %s:\n%s",
1401+
server_name,
1402+
_format_exception_details(e),
1403+
exc_info=True,
1404+
)
13821405
continue
13831406

13841407
return final_tools

0 commit comments

Comments
 (0)