Skip to content

Commit 78490e3

Browse files
committed
fix: improve error handling in agent connection and update logging messages
1 parent 0c902cd commit 78490e3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

adf_core_python/core/agent/agent.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ def update_step_info(
197197
message_manager=self._message_manager,
198198
)
199199

200+
a = 1 / 0
201+
200202
self._message_manager.coordinate_message(
201203
self._agent_info, self._world_info, self._scenario_info
202204
)
@@ -228,9 +230,18 @@ def message_received(self, msg: Any) -> None:
228230
self.handle_connect_error(c_msg)
229231

230232
def handle_connect_error(self, msg: Any) -> NoReturn:
231-
self.logger.error(
232-
"Failed to connect agent: %s(request_id: %s)", msg.reason, msg.request_id
233-
)
233+
if msg.reason.startswith("No more agents"):
234+
self.logger.debug(
235+
"Agent already connected: %s(request_id: %s)",
236+
msg.reason,
237+
msg.request_id,
238+
)
239+
else:
240+
self.logger.error(
241+
"Failed to connect agent: %s(request_id: %s)",
242+
msg.reason,
243+
msg.request_id,
244+
)
234245
sys.exit(1)
235246

236247
def handle_connect_ok(self, msg: Any) -> None:

adf_core_python/core/launcher/connect/component_launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def connect(self, agent: Agent, _request_id: int) -> None:
4747
connection.parse_message_from_kernel()
4848
except Exception as e:
4949
self.logger.exception(
50-
f"Failed to connect agent: {self.host}:{self.port} {e}",
50+
f"Agent threw an exception {e}",
5151
exception=str(e),
5252
)
5353

0 commit comments

Comments
 (0)