fix: improve error handling for lexer exceptions in AutoCompleter and RepoMap

This commit is contained in:
Paul Gauthier 2024-08-28 22:49:22 -07:00 committed by Paul Gauthier (aider)
parent ce397b71e8
commit ad3f29bdce
2 changed files with 5 additions and 2 deletions

View file

@ -82,8 +82,10 @@ class AutoCompleter(Completer):
continue
try:
lexer = guess_lexer_for_filename(fname, content)
except Exception: # On Windows, bad ref to time.clock which is deprecated
except Exception as ex: # On Windows, bad ref to time.clock which is deprecated
self.tool_error(f"Error lexing {fname}: {ex}")
continue
tokens = list(lexer.get_tokens(content))
self.words.update(
(token[1], f"`{token[1]}`") for token in tokens if token[0] in Token.Name

View file

@ -252,7 +252,8 @@ class RepoMap:
try:
lexer = guess_lexer_for_filename(fname, code)
except Exception: # On Windows, bad ref to time.clock which is deprecated
except Exception as ex: # On Windows, bad ref to time.clock which is deprecated?
self.io.tool_error(f"Error lexing {fname}: {ex}")
return
tokens = list(lexer.get_tokens(code))