mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
fix: Handle api key error (#488)
* Propagate exception up to task coroutine instead of breaking the for loop manually, await coroutine so exception is returned to caller * Remove redundant traceback as is already called in step function lower on the stack * Change message as error could occur in middle of task also * Fix linter errors * Raise exception only on api key error * Add TODO
This commit is contained in:
@@ -63,8 +63,7 @@ class AgentController:
|
||||
finished = await self.step(i)
|
||||
except Exception as e:
|
||||
print("Error in loop", e, flush=True)
|
||||
traceback.print_exc()
|
||||
break
|
||||
raise e
|
||||
if finished:
|
||||
break
|
||||
if not finished:
|
||||
@@ -94,6 +93,9 @@ class AgentController:
|
||||
observation = AgentErrorObservation(str(e))
|
||||
print_with_indent("\nAGENT ERROR:\n%s" % observation)
|
||||
traceback.print_exc()
|
||||
# TODO Change to more robust error handling
|
||||
if "The api_key client option must be set" in observation.content:
|
||||
raise
|
||||
self.update_state_after_step()
|
||||
|
||||
await self._run_callbacks(action)
|
||||
|
||||
@@ -156,7 +156,10 @@ class Session:
|
||||
if self.controller is None:
|
||||
await self.send_error("No agent started. Please wait a second...")
|
||||
return
|
||||
self.agent_task = asyncio.create_task(self.controller.start_loop(task), name="agent loop")
|
||||
try:
|
||||
self.agent_task = await asyncio.create_task(self.controller.start_loop(task), name="agent loop")
|
||||
except Exception:
|
||||
await self.send_error("Error during task loop.")
|
||||
|
||||
def on_agent_event(self, event: Observation | Action):
|
||||
"""Callback function for agent events.
|
||||
|
||||
Reference in New Issue
Block a user