Skip to content

Commit

Permalink
refactor: improve SQLite error handling and logging in tags cache
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-gauthier committed Oct 29, 2024
1 parent adca062 commit 0424e4b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions aider/repomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ def get_rel_fname(self, fname):

def tags_cache_error(self, original_error=None):
"""Handle SQLite errors by trying to recreate cache, falling back to dict if needed"""

if self.verbose and original_error:
self.io.tool_warning(f"Tags cache error: {str(original_error)}")

if isinstance(getattr(self, "TAGS_CACHE", None), dict):
return

Expand Down Expand Up @@ -199,8 +203,6 @@ def tags_cache_error(self, original_error=None):
f"Unable to use tags cache at {path}, falling back to memory cache"
)
if self.verbose:
if original_error:
self.io.tool_warning(f"Original error: {str(original_error)}")
self.io.tool_warning(f"Cache recreation error: {str(e)}")

self.TAGS_CACHE = dict()
Expand Down Expand Up @@ -237,8 +239,8 @@ def get_tags(self, fname, rel_fname):
if val is not None and val.get("mtime") == file_mtime:
try:
return self.TAGS_CACHE[cache_key]["data"]
except SQLITE_ERRORS:
self.tags_cache_error()
except SQLITE_ERRORS as e:
self.tags_cache_error(e)
return self.TAGS_CACHE[cache_key]["data"]

# miss!
Expand All @@ -248,8 +250,8 @@ def get_tags(self, fname, rel_fname):
try:
self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data}
self.save_tags_cache()
except SQLITE_ERRORS:
self.tags_cache_error()
except SQLITE_ERRORS as e:
self.tags_cache_error(e)
self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data}

return data
Expand Down Expand Up @@ -352,8 +354,8 @@ def get_ranked_tags(

try:
cache_size = len(self.TAGS_CACHE)
except SQLITE_ERRORS:
self.tags_cache_error()
except SQLITE_ERRORS as e:
self.tags_cache_error(e)
cache_size = len(self.TAGS_CACHE)

if len(fnames) - cache_size > 100:
Expand Down

0 comments on commit 0424e4b

Please sign in to comment.