Răsfoiți Sursa

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
George Balch 1 an în urmă
părinte
comite
a9f469f0e7
2 a modificat fișierele cu 8 adăugiri și 3 ștergeri
  1. 4 2
      opendevin/controller/agent_controller.py
  2. 4 1
      opendevin/server/session.py

+ 4 - 2
opendevin/controller/agent_controller.py

@@ -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)

+ 4 - 1
opendevin/server/session.py

@@ -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.