Skip to content

Commit

Permalink
repomap.get_tags_raw doesn't crash on UTF-16 files
Browse files Browse the repository at this point in the history
Related to #305, Aider would crash while building a repomap when attempting to load a file with non UTF-16 content. This commit adds a try/except block that returns nothing back to the caller, allowing repomap to skip the file and continue.

Future considerations might be to use the read_file function in `io.py`

I've not run any tests other than ensuring that `/tokens` does not crash when a non UTF-8 file is present in the Git repo.
  • Loading branch information
nevercast authored Nov 2, 2023
1 parent 0875300 commit e49e8fc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions aider/repomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ def get_tags_raw(self, fname, rel_fname):
return
query_scm = query_scm.read_text()

code = Path(fname).read_text(encoding=self.io.encoding)
tree = parser.parse(bytes(code, "utf-8"))
try:
code = Path(fname).read_text(encoding=self.io.encoding)
tree = parser.parse(bytes(code, "utf-8"))
except UnicodeDecodeError:
return

# Run the tags queries
query = language.query(query_scm)
Expand Down

0 comments on commit e49e8fc

Please sign in to comment.