From 25c36503ff50838084cf2b75ed40c7255188340a Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Fri, 9 Aug 2024 16:32:15 -0300 Subject: [PATCH] fix: Handle non-existent files in apply_edits --- aider/coders/base_coder.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index b712d00ed..2e7b8b659 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -1658,4 +1658,14 @@ class Coder: return [] def apply_edits(self, edits): + for edit in edits: + path, content = edit + full_path = self.abs_root_path(path) + if not os.path.exists(full_path): + self.io.tool_error(f"Error: File {path} does not exist. Skipping edits.") + continue + + if not self.dry_run: + with open(full_path, 'w', encoding=self.io.encoding) as f: + f.write(content) return