mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Send the permission error to the llm (#1343)
* Send the permission error to the llm * Update opendevin/action/fileop.py * Update opendevin/action/fileop.py --------- Co-authored-by: Robert Brennan <accounts@rbren.io>
This commit is contained in:
parent
fde0392457
commit
bd470e8076
@ -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]
|
||||
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}')
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user