Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Enh(tools): Better warning if dir doesn't exist

Kilian Lieret7fef6cfc769e
diff --git a/tools/edit_anthropic/bin/str_replace_editor b/tools/edit_anthropic/bin/str_replace_editor
index a04a07ca..84fd0a33 100644
--- a/tools/edit_anthropic/bin/str_replace_editor
+++ b/tools/edit_anthropic/bin/str_replace_editor
@@ -373,9 +373,7 @@ class EditTool:
if file_text is None:
print("Parameter `file_text` is required for command: create")
sys.exit(1)
- self.write_file(_path, file_text)
- self._file_history[_path].append(file_text)
- print(f"File created successfully at: {_path}")
+ self.create_file(_path, file_text)
return None
elif command == "str_replace":
if old_str is None:
@@ -421,6 +419,14 @@ class EditTool:
print(f"The path {path} is a directory and only the `view` command can be used on directories")
sys.exit(9)
+ def create_file(self, path: Path, file_text: str):
+ if not path.parent.exists():
+ print(f"The parent directory {path.parent} does not exist. Please create it first.")
+ sys.exit(21)
+ self.write_file(path, file_text)
+ self._file_history[path].append(file_text)
+ print(f"File created successfully at: {path}")
+
def view(self, path: Path, view_range: Optional[List[int]] = None):
"""Implement the view command"""
if path.is_dir():