From 3cd6790d9a79e7c500b2a2da7927ec9505476c8d Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 9 Sep 2024 13:37:24 -0700 Subject: [PATCH] fix: handle OSError in git repo operations --- aider/repo.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/aider/repo.py b/aider/repo.py index 369761233..ca6c0102f 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -10,7 +10,7 @@ from aider.sendchat import simple_send_with_retries from .dump import dump # noqa: F401 -ANY_GIT_ERROR = (git.exc.ODBError, git.exc.GitError) +ANY_GIT_ERROR = (git.exc.ODBError, git.exc.GitError, OSError) class GitRepo: @@ -257,7 +257,7 @@ class GitRepo: commit = self.repo.head.commit except ValueError: commit = None - except (OSError,) + ANY_GIT_ERROR as err: + except ANY_GIT_ERROR as err: self.io.tool_error(f"Unable to list files in git repo: {err}") self.io.tool_output("Is your git repo corrupted?") return [] @@ -267,9 +267,14 @@ class GitRepo: if commit in self.tree_files: files = self.tree_files[commit] else: - for blob in commit.tree.traverse(): - if blob.type == "blob": # blob is a file - files.add(blob.path) + try: + for blob in commit.tree.traverse(): + if blob.type == "blob": # blob is a file + files.add(blob.path) + except ANY_GIT_ERROR as err: + self.io.tool_error(f"Unable to list files in git repo: {err}") + self.io.tool_output("Is your git repo corrupted?") + return [] files = set(self.normalize_path(path) for path in files) self.tree_files[commit] = set(files)