handle IsADirectory errors (#1365)

This commit is contained in:
Robert Brennan
2024-04-25 15:15:06 -04:00
committed by GitHub
parent 110e7f0c4c
commit f407382a5a

View File

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