Skip to content

fix: add debug logging for programming exceptions caught by ANY_GIT_ERROR#4945

Open
ernestodeoliveira wants to merge 1 commit intoAider-AI:mainfrom
ernestodeoliveira:fix/log-programming-exceptions-in-any-git-error
Open

fix: add debug logging for programming exceptions caught by ANY_GIT_ERROR#4945
ernestodeoliveira wants to merge 1 commit intoAider-AI:mainfrom
ernestodeoliveira:fix/log-programming-exceptions-in-any-git-error

Conversation

@ernestodeoliveira
Copy link
Copy Markdown

Summary

Addresses #4932.

ANY_GIT_ERROR includes TypeError, ValueError, AttributeError, and AssertionError — exception types that signal programming bugs, not git errors. When silently caught at 22+ call sites, real bugs become invisible: users see a vague message instead of a traceback, and bug reports are much harder to diagnose.

Changes

Phase 1 — Observability (this PR)

Added logger.debug() before every silent except ANY_GIT_ERROR block across four files:

  • aider/repo.py — 8 call sites
  • aider/coders/base_coder.py — 2 call sites (apply_updates, auto_commit)
  • aider/commands.py — 5 call sites (do_run, cmd_commit, cmd_undo, cmd_diff)
  • aider/main.py — 5 call sites (guessed_wrong_repo, make_new_repo, setup_git, check_gitignore, sanity_check_repo)

Format is consistent across all sites:

logger.debug("Caught %s in <function>: %s", type(e).__name__, e, exc_info=True)

exc_info=True ensures the full traceback appears in debug logs, making hidden bugs fully visible.

Redundancy fix

repo.py:384 wrote (TypeError,) + ANY_GIT_ERROR — manually prepending TypeError when it is already a member of the tuple. Same issue in get_head_commit with (ValueError,). Both simplified to plain ANY_GIT_ERROR, removing the evidence of confusion noted in the issue.

What this does NOT change

  • No user-visible behavior changes
  • No exceptions removed from ANY_GIT_ERROR (that is Phase 2 work)
  • No new dependencies

Testing

Added tests/basic/test_any_git_error_logging.py with a test that:

  1. Mocks repo.ignored() to raise TypeError (a programming bug)
  2. Calls git_ignored_file() through the real code path
  3. Asserts logger.debug was called with the correct function name, exception type, and exc_info=True

Next steps (Phase 2)

Once Phase 1 is in and debug logs are available in the wild, the remaining work is to audit which call sites legitimately need TypeError/AttributeError (where gitpython itself raises them) vs. which are cargo-cult catches that can be narrowed. Happy to continue that work in a follow-up PR.

…RROR

ANY_GIT_ERROR includes TypeError, ValueError, AttributeError, and
AssertionError — exception types that indicate programming bugs, not
git errors. When these are silently caught at 22+ call sites, real
bugs become invisible to users and developers (issue Aider-AI#4932).

This commit adds logger.debug() before every silent except ANY_GIT_ERROR
block, so programming exceptions surface in debug logs without changing
any user-visible behavior.

Also fixes a redundant (TypeError,) + ANY_GIT_ERROR in repo.py:384 and
get_head_commit: since TypeError and ValueError are already members of
ANY_GIT_ERROR, the manual prepend was a no-op that indicated the tuple
contents were not well-understood.

No behavior changes for users. All existing functionality preserved.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 20, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants