Skip to content

πŸ™Œ OpenHands: AI-Driven Development

hotfix(backend): Handle errors when executing run actions (#8160)

sp.wack1ffaae17ff1c
diff --git a/openhands/runtime/action_execution_server.py b/openhands/runtime/action_execution_server.py
index b0a17a671d..d91126202c 100644
--- a/openhands/runtime/action_execution_server.py
+++ b/openhands/runtime/action_execution_server.py
@@ -309,19 +309,23 @@ class ActionExecutor:
async def run(
self, action: CmdRunAction
) -> CmdOutputObservation | ErrorObservation:
- if action.is_static:
- path = action.cwd or self._initial_cwd
- result = await AsyncBashSession.execute(action.command, path)
- obs = CmdOutputObservation(
- content=result.content,
- exit_code=result.exit_code,
- command=action.command,
- )
- return obs
+ try:
+ if action.is_static:
+ path = action.cwd or self._initial_cwd
+ result = await AsyncBashSession.execute(action.command, path)
+ obs = CmdOutputObservation(
+ content=result.content,
+ exit_code=result.exit_code,
+ command=action.command,
+ )
+ return obs
- assert self.bash_session is not None
- obs = await call_sync_from_async(self.bash_session.execute, action)
- return obs
+ assert self.bash_session is not None
+ obs = await call_sync_from_async(self.bash_session.execute, action)
+ return obs
+ except Exception as e:
+ logger.error(f'Error running command: {e}')
+ return ErrorObservation(str(e))
async def run_ipython(self, action: IPythonRunCellAction) -> Observation:
assert self.bash_session is not None