π OpenHands: AI-Driven Development
Send the permission error to the llm (#1343)
Engel Nystbd470e8076c1
diff --git a/opendevin/action/fileop.py b/opendevin/action/fileop.pyindex 59332d2b37..07be0388a3 100644--- a/opendevin/action/fileop.py+++ b/opendevin/action/fileop.py@@ -69,14 +69,17 @@ class FileReadAction(ExecutableAction):read_lines = self._read_lines(content.split('\n'))code_view = ''.join(read_lines)else:- whole_path = resolve_path(self.path)- self.start = max(self.start, 0)try:- with open(whole_path, 'r', encoding='utf-8') as file:- read_lines = self._read_lines(file.readlines())- code_view = ''.join(read_lines)- except FileNotFoundError:- return AgentErrorObservation(f'File not found: {self.path}')+ whole_path = resolve_path(self.path)+ self.start = max(self.start, 0)+ try:+ with open(whole_path, 'r', encoding='utf-8') as file:+ read_lines = self._read_lines(file.readlines())+ code_view = ''.join(read_lines)+ except FileNotFoundError:+ return AgentErrorObservation(f'File not found: {self.path}')+ except PermissionError:+ return AgentErrorObservation(f'Malformed paths not permitted: {self.path}')return FileReadObservation(path=self.path, content=code_view)@property@@ -114,21 +117,24 @@ class FileWriteAction(ExecutableAction):else:return AgentErrorObservation(f'File not found: {self.path}')else:- whole_path = resolve_path(self.path)- mode = 'w' if not os.path.exists(whole_path) else 'r+'try:- with open(whole_path, mode, encoding='utf-8') as file:- if mode != 'w':- all_lines = file.readlines()- new_file = self._insert_lines(insert, all_lines)- else:- new_file = [i + '\n' for i in insert]-- file.seek(0)- file.writelines(new_file)- file.truncate()- except FileNotFoundError:- return AgentErrorObservation(f'File not found: {self.path}')+ whole_path = resolve_path(self.path)+ mode = 'w' if not os.path.exists(whole_path) else 'r+'+ try:+ with open(whole_path, mode, encoding='utf-8') as file:+ if mode != 'w':+ all_lines = file.readlines()+ new_file = self._insert_lines(insert, all_lines)+ else:+ new_file = [i + '\n' for i in insert]++ file.seek(0)+ file.writelines(new_file)+ file.truncate()+ except FileNotFoundError:+ return AgentErrorObservation(f'File not found: {self.path}')+ except PermissionError:+ return AgentErrorObservation(f'Malformed paths not permitted: {self.path}')return FileWriteObservation(content='', path=self.path)@property