Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions aider/coders/base_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import hashlib
import json
import locale
import logging
import math
import mimetypes
import os
Expand Down Expand Up @@ -52,6 +53,8 @@
from ..dump import dump # noqa: F401
from .chat_chunks import ChatChunks

logger = logging.getLogger(__name__)


class UnknownEditFormat(ValueError):
def __init__(self, edit_format, valid_formats):
Expand Down Expand Up @@ -2316,6 +2319,7 @@ def apply_updates(self):
return edited

except ANY_GIT_ERROR as err:
logger.debug("Caught %s in apply_updates: %s", type(err).__name__, err, exc_info=True)
self.io.tool_error(str(err))
return edited
except Exception as err:
Expand Down Expand Up @@ -2391,6 +2395,7 @@ def auto_commit(self, edited, context=None):

return self.gpt_prompts.files_content_gpt_no_edits
except ANY_GIT_ERROR as err:
logger.debug("Caught %s in auto_commit: %s", type(err).__name__, err, exc_info=True)
self.io.tool_error(f"Unable to commit: {str(err)}")
return

Expand Down
13 changes: 11 additions & 2 deletions aider/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import glob
import logging
import os
import re
import subprocess
Expand Down Expand Up @@ -26,6 +27,8 @@

from .dump import dump # noqa: F401

logger = logging.getLogger(__name__)


class SwitchCoder(Exception):
def __init__(self, placeholder=None, **kwargs):
Expand Down Expand Up @@ -295,6 +298,7 @@ def do_run(self, cmd_name, args):
try:
return cmd_method(args)
except ANY_GIT_ERROR as err:
logger.debug("Caught %s in do_run: %s", type(err).__name__, err, exc_info=True)
self.io.tool_error(f"Unable to complete {cmd_name}: {err}")

def matching_commands(self, inp):
Expand Down Expand Up @@ -339,6 +343,7 @@ def cmd_commit(self, args=None):
try:
self.raw_cmd_commit(args)
except ANY_GIT_ERROR as err:
logger.debug("Caught %s in cmd_commit: %s", type(err).__name__, err, exc_info=True)
self.io.tool_error(f"Unable to complete commit: {err}")

def raw_cmd_commit(self, args=None):
Expand Down Expand Up @@ -555,6 +560,7 @@ def cmd_undo(self, args):
try:
self.raw_cmd_undo(args)
except ANY_GIT_ERROR as err:
logger.debug("Caught %s in cmd_undo: %s", type(err).__name__, err, exc_info=True)
self.io.tool_error(f"Unable to complete undo: {err}")

def raw_cmd_undo(self, args):
Expand Down Expand Up @@ -609,7 +615,8 @@ def raw_cmd_undo(self, args):
try:
remote_head = self.coder.repo.repo.git.rev_parse(f"origin/{current_branch}")
has_origin = True
except ANY_GIT_ERROR:
except ANY_GIT_ERROR as e:
logger.debug("Caught %s in raw_cmd_undo: %s", type(e).__name__, e, exc_info=True)
has_origin = False

if has_origin:
Expand All @@ -627,7 +634,8 @@ def raw_cmd_undo(self, args):
try:
self.coder.repo.repo.git.checkout("HEAD~1", file_path)
restored.add(file_path)
except ANY_GIT_ERROR:
except ANY_GIT_ERROR as e:
logger.debug("Caught %s in raw_cmd_undo: %s", type(e).__name__, e, exc_info=True)
unrestored.add(file_path)

if unrestored:
Expand Down Expand Up @@ -659,6 +667,7 @@ def cmd_diff(self, args=""):
try:
self.raw_cmd_diff(args)
except ANY_GIT_ERROR as err:
logger.debug("Caught %s in cmd_diff: %s", type(err).__name__, err, exc_info=True)
self.io.tool_error(f"Unable to complete diff: {err}")

def raw_cmd_diff(self, args=""):
Expand Down
15 changes: 11 additions & 4 deletions aider/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import os
import re
import sys
Expand Down Expand Up @@ -39,6 +40,8 @@

from .dump import dump # noqa: F401

logger = logging.getLogger(__name__)


def check_config_files_for_yes(config_files):
found = False
Expand Down Expand Up @@ -71,7 +74,8 @@ def guessed_wrong_repo(io, git_root, fnames, git_dname):

try:
check_repo = Path(GitRepo(io, fnames, git_dname).root).resolve()
except (OSError,) + ANY_GIT_ERROR:
except ANY_GIT_ERROR as e:
logger.debug("Caught %s in guessed_wrong_repo: %s", type(e).__name__, e, exc_info=True)
return

# we had no guess, rely on the "true" repo result
Expand All @@ -90,6 +94,7 @@ def make_new_repo(git_root, io):
repo = git.Repo.init(git_root)
check_gitignore(git_root, io, False)
except ANY_GIT_ERROR as err: # issue #1233
logger.debug("Caught %s in make_new_repo: %s", type(err).__name__, err, exc_info=True)
io.tool_error(f"Unable to create git repo in {git_root}")
io.tool_output(str(err))
return
Expand All @@ -112,8 +117,8 @@ def setup_git(git_root, io):
if git_root:
try:
repo = git.Repo(git_root)
except ANY_GIT_ERROR:
pass
except ANY_GIT_ERROR as e:
logger.debug("Caught %s in setup_git: %s", type(e).__name__, e, exc_info=True)
elif cwd == Path.home():
io.tool_warning(
"You should probably run aider in your project's directory, not your home dir."
Expand Down Expand Up @@ -183,7 +188,8 @@ def check_gitignore(git_root, io, ask=True):
return
else:
content = ""
except ANY_GIT_ERROR:
except ANY_GIT_ERROR as e:
logger.debug("Caught %s in check_gitignore: %s", type(e).__name__, e, exc_info=True)
return

if ask:
Expand Down Expand Up @@ -430,6 +436,7 @@ def sanity_check_repo(repo, io):
f"Internal error: {str(exc)}"
)
except ANY_GIT_ERROR as exc:
logger.debug("Caught %s in main: %s", type(exc).__name__, exc, exc_info=True)
error_msg = str(exc)
bad_ver = "version in (1, 2)" in error_msg
except AssertionError as exc:
Expand Down
27 changes: 19 additions & 8 deletions aider/repo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
import logging
import os
import time
from pathlib import Path, PurePosixPath
Expand Down Expand Up @@ -35,6 +36,8 @@
]
ANY_GIT_ERROR = tuple(ANY_GIT_ERROR)

logger = logging.getLogger(__name__)


@contextlib.contextmanager
def set_git_env(var_name, value, original_value):
Expand Down Expand Up @@ -110,8 +113,8 @@ def __init__(
repo_path = git.Repo(fname, search_parent_directories=True).working_dir
repo_path = utils.safe_abs_path(repo_path)
repo_paths.append(repo_path)
except ANY_GIT_ERROR:
pass
except ANY_GIT_ERROR as e:
logger.debug("Caught %s in __init__: %s", type(e).__name__, e, exc_info=True)

num_repos = len(set(repo_paths))

Expand Down Expand Up @@ -283,6 +286,7 @@ def commit(self, fnames=None, context=None, message=None, aider_edits=False, cod
try:
self.repo.git.add(fname)
except ANY_GIT_ERROR as err:
logger.debug("Caught %s in commit: %s", type(err).__name__, err, exc_info=True)
self.io.tool_error(f"Unable to add {fname}: {err}")
cmd += ["--"] + fnames
else:
Expand Down Expand Up @@ -314,6 +318,7 @@ def commit(self, fnames=None, context=None, message=None, aider_edits=False, cod
return commit_hash, commit_message

except ANY_GIT_ERROR as err:
logger.debug("Caught %s in commit: %s", type(err).__name__, err, exc_info=True)
self.io.tool_error(f"Unable to commit: {err}")
# No return here, implicitly returns None

Expand Down Expand Up @@ -381,10 +386,10 @@ def get_diffs(self, fnames=None):
try:
commits = self.repo.iter_commits(active_branch)
current_branch_has_commits = any(commits)
except ANY_GIT_ERROR:
pass
except (TypeError,) + ANY_GIT_ERROR:
pass
except ANY_GIT_ERROR as e:
logger.debug("Caught %s in get_diffs: %s", type(e).__name__, e, exc_info=True)
except ANY_GIT_ERROR as e:
logger.debug("Caught %s in get_diffs: %s", type(e).__name__, e, exc_info=True)

if not fnames:
fnames = []
Expand Down Expand Up @@ -414,6 +419,7 @@ def get_diffs(self, fnames=None):

return diffs
except ANY_GIT_ERROR as err:
logger.debug("Caught %s in get_diffs: %s", type(err).__name__, err, exc_info=True)
self.io.tool_error(f"Unable to diff: {err}")

def diff_commits(self, pretty, from_commit, to_commit):
Expand All @@ -439,6 +445,7 @@ def get_tracked_files(self):
except ValueError:
commit = None
except ANY_GIT_ERROR as err:
logger.debug("Caught %s in get_tracked_files: %s", type(err).__name__, err, exc_info=True)
self.git_repo_error = err
self.io.tool_error(f"Unable to list files in git repo: {err}")
self.io.tool_output("Is your git repo corrupted?")
Expand Down Expand Up @@ -468,6 +475,7 @@ def get_tracked_files(self):
except StopIteration:
break
except ANY_GIT_ERROR as err:
logger.debug("Caught %s in get_tracked_files: %s", type(err).__name__, err, exc_info=True)
self.git_repo_error = err
self.io.tool_error(f"Unable to list files in git repo: {err}")
self.io.tool_output("Is your git repo corrupted?")
Expand All @@ -481,6 +489,7 @@ def get_tracked_files(self):
staged_files = [path for path, _ in index.entries.keys()]
files.update(self.normalize_path(path) for path in staged_files)
except ANY_GIT_ERROR as err:
logger.debug("Caught %s in get_tracked_files: %s", type(err).__name__, err, exc_info=True)
self.io.tool_error(f"Unable to read staged files: {err}")

res = [fname for fname in files if not self.ignored_file(fname)]
Expand Down Expand Up @@ -526,7 +535,8 @@ def git_ignored_file(self, path):
try:
if self.repo.ignored(path):
return True
except ANY_GIT_ERROR:
except ANY_GIT_ERROR as e:
logger.debug("Caught %s in git_ignored_file: %s", type(e).__name__, e, exc_info=True)
return False

def ignored_file(self, fname):
Expand Down Expand Up @@ -604,7 +614,8 @@ def is_dirty(self, path=None):
def get_head_commit(self):
try:
return self.repo.head.commit
except (ValueError,) + ANY_GIT_ERROR:
except ANY_GIT_ERROR as e:
logger.debug("Caught %s in get_head_commit: %s", type(e).__name__, e, exc_info=True)
return None

def get_head_commit_sha(self, short=False):
Expand Down
26 changes: 26 additions & 0 deletions tests/basic/test_any_git_error_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import logging
from unittest import mock

from aider.repo import ANY_GIT_ERROR, GitRepo


def test_git_ignored_file_logs_debug_on_any_git_error():
"""Verify that debug logging fires when a programming exception
is caught by except ANY_GIT_ERROR."""
# Set up a minimal GitRepo-like object with a mock repo
repo = mock.MagicMock()
repo.ignored.side_effect = TypeError("simulated programming bug")

git_repo = mock.MagicMock(spec=GitRepo)
git_repo.repo = repo

# Call the real method with our mocked object
with mock.patch("aider.repo.logger") as mock_logger:
result = GitRepo.git_ignored_file(git_repo, "somefile.py")

assert result is False
mock_logger.debug.assert_called_once()
call_args = mock_logger.debug.call_args
assert "TypeError" in str(call_args)
assert "git_ignored_file" in str(call_args)
assert call_args.kwargs.get("exc_info") is True