From b6142af12b4b2c056f7c64c342f2d7ba8b49188e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 25 Oct 2023 15:52:26 -0700 Subject: [PATCH] make sure **.txt does not crash chat #293 --- aider/commands.py | 6 +++++- tests/test_commands.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/aider/commands.py b/aider/commands.py index 63291a72d..fa504c5e7 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -253,7 +253,11 @@ class Commands: yield Completion(fname, start_position=-len(partial)) def glob_filtered_to_repo(self, pattern): - raw_matched_files = list(Path(self.coder.root).glob(pattern)) + try: + raw_matched_files = list(Path(self.coder.root).glob(pattern)) + except ValueError as err: + self.io.tool_error(f"Error matching {pattern}: {err}") + raw_matched_files = [] matched_files = [] for fn in raw_matched_files: diff --git a/tests/test_commands.py b/tests/test_commands.py index 89524e73b..97a260e57 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -42,6 +42,17 @@ class TestCommands(TestCase): self.assertTrue(os.path.exists("foo.txt")) self.assertTrue(os.path.exists("bar.txt")) + def test_cmd_add_bad_glob(self): + # https://github.com/paul-gauthier/aider/issues/293 + + io = InputOutput(pretty=False, yes=True) + from aider.coders import Coder + + coder = Coder.create(models.GPT35, None, io) + commands = Commands(io, coder) + + commands.cmd_add("**.txt") + def test_cmd_add_with_glob_patterns(self): # Initialize the Commands and InputOutput objects io = InputOutput(pretty=False, yes=True)