From c2c80bbd3cef8db0a81e2a6249b4bbfc76a4b443 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 5 Jul 2023 21:00:10 -0700 Subject: [PATCH] do not /add files that fail to decode --- aider/commands.py | 8 +++++--- aider/io.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index a262f9c8d..e3b3ee441 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -252,9 +252,11 @@ class Commands: for matched_file in matched_files: abs_file_path = os.path.abspath(os.path.join(self.coder.root, matched_file)) if abs_file_path not in self.coder.abs_fnames: - self.coder.abs_fnames.add(abs_file_path) - self.io.tool_output(f"Added {matched_file} to the chat") - added_fnames.append(matched_file) + content = self.io.read_text(abs_file_path) + if content is not None: + self.coder.abs_fnames.add(abs_file_path) + self.io.tool_output(f"Added {matched_file} to the chat") + added_fnames.append(matched_file) else: self.io.tool_error(f"{matched_file} is already in the chat") diff --git a/aider/io.py b/aider/io.py index f001d63f5..5f045ad4d 100644 --- a/aider/io.py +++ b/aider/io.py @@ -140,7 +140,7 @@ class InputOutput: with open(filename, "r", encoding=self.encoding) as f: return f.read() except (FileNotFoundError, UnicodeError) as e: - self.tool_error(str(e)) + self.tool_error(f"{filename}: {e}") return def get_input(self, root, rel_fnames, addable_rel_fnames, commands):