aider icon indicating copy to clipboard operation
aider copied to clipboard

Getting BadObject error when running Aider

Open avi-cenna opened this issue 1 year ago • 1 comments

Issue

I am running into a git BadObject error. I'm not sure why this is arising. I had it once before and I just re-cloned the repo and then it started working.

This is the full error message:

 ❯ aider [my_file.py]
Traceback (most recent call last):
  File "/Users/johndoe/.local/bin/aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/johndoe/.local/pipx/venvs/aider-chat/lib/python3.11/site-packages/aider/main.py", line 346, in main
    coder.show_announcements()
  File "/Users/johndoe/.local/pipx/venvs/aider-chat/lib/python3.11/site-packages/aider/coders/base_coder.py", line 298, in show_announcements
    for line in self.get_announcements():
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/johndoe/.local/pipx/venvs/aider-chat/lib/python3.11/site-packages/aider/coders/base_coder.py", line 133, in get_announcements
    num_files = len(self.repo.get_tracked_files())
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/johndoe/.local/pipx/venvs/aider-chat/lib/python3.11/site-packages/aider/repo.py", line 194, in get_tracked_files
    for blob in commit.tree.traverse():
  File "/Users/johndoe/.local/pipx/venvs/aider-chat/lib/python3.11/site-packages/git/objects/util.py", line 575, in _traverse
    addToStack(stack, item, branch_first, nd)
  File "/Users/johndoe/.local/pipx/venvs/aider-chat/lib/python3.11/site-packages/git/objects/util.py", line 535, in addToStack
    lst = self._get_intermediate_items(item)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/johndoe/.local/pipx/venvs/aider-chat/lib/python3.11/site-packages/git/objects/tree.py", line 207, in _get_intermediate_items
    return tuple(index_object._iter_convert_to_object(index_object._cache))
                                                      ^^^^^^^^^^^^^^^^^^^
  File "/Users/johndoe/.local/pipx/venvs/aider-chat/lib/python3.11/site-packages/gitdb/util.py", line 253, in __getattr__
    self._set_cache_(attr)
  File "/Users/johndoe/.local/pipx/venvs/aider-chat/lib/python3.11/site-packages/git/objects/tree.py", line 213, in _set_cache_
    ostream = self.repo.odb.stream(self.binsha)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/johndoe/.local/pipx/venvs/aider-chat/lib/python3.11/site-packages/gitdb/db/base.py", line 213, in stream
    return self._db_query(sha).stream(sha)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/johndoe/.local/pipx/venvs/aider-chat/lib/python3.11/site-packages/gitdb/db/base.py", line 197, in _db_query
    raise BadObject(sha)
gitdb.exc.BadObject: BadObject: b'4ad4ff262c9d5557e4e08899715365b5bd1af1c1'

However, when I look at that object in git, it appears to be a valid object.

 ❯ git show 4ad4ff262c9d5557e4e08899715365b5bd1af1c1
tree 4ad4ff262c9d5557e4e08899715365b5bd1af1c1

[file1]
[file2]
...

I'm not sure if this would make sense, but maybe there needs to be a try-catch block in the code to just skip over objects that for some reason appear to be bad objects and simply print a warning to the user.

Version and model info

aider 0.31.1 Git repo with 100,000+ files Default GPT model settings

avi-cenna avatar May 03 '24 17:05 avi-cenna

Thanks for trying aider and filing this issue. My best guess is that something was corrupt about your git repo. The fact that it works with a fresh clone of the repo seems to support that.

Unfortunately, it's not wise for aider to catch and ignore this error. It's happening while aider is trying to get the list of all the files in the repo, which it needs to operate. If the repo is damaged to the point where it can't list the files, aider should probably not try and proceed.

paul-gauthier avatar May 03 '24 20:05 paul-gauthier

Thanks for your response. I found that my issue was indeed related to corruption in my repo. Here is what I did to resolve my issue, without have to do a fresh clone of the repo.

  1. Run git fsck --full When I ran this, I noticed several dangling commit or dangling blob messages.
  2. Run git gc --prune=now This cleared the issues identified in step 1 above.

Aider is now working for me again; I will close this issue.

avi-cenna avatar May 06 '24 14:05 avi-cenna