mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
handle IsADirectory errors (#1365)
This commit is contained in:
@@ -78,6 +78,8 @@ class FileReadAction(ExecutableAction):
|
||||
code_view = ''.join(read_lines)
|
||||
except FileNotFoundError:
|
||||
return AgentErrorObservation(f'File not found: {self.path}')
|
||||
except IsADirectoryError:
|
||||
return AgentErrorObservation(f'Path is a directory: {self.path}. You can only read files')
|
||||
except PermissionError:
|
||||
return AgentErrorObservation(f'Malformed paths not permitted: {self.path}')
|
||||
return FileReadObservation(path=self.path, content=code_view)
|
||||
@@ -133,6 +135,8 @@ class FileWriteAction(ExecutableAction):
|
||||
file.truncate()
|
||||
except FileNotFoundError:
|
||||
return AgentErrorObservation(f'File not found: {self.path}')
|
||||
except IsADirectoryError:
|
||||
return AgentErrorObservation(f'Path is a directory: {self.path}. You can only write to files')
|
||||
except PermissionError:
|
||||
return AgentErrorObservation(f'Malformed paths not permitted: {self.path}')
|
||||
return FileWriteObservation(content='', path=self.path)
|
||||
|
||||
Reference in New Issue
Block a user