mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
refactor: improve SQLite error handling and logging in tags cache
This commit is contained in:
parent
adca062081
commit
0424e4b00a
1 changed files with 10 additions and 8 deletions
|
@ -169,6 +169,10 @@ class RepoMap:
|
||||||
|
|
||||||
def tags_cache_error(self, original_error=None):
|
def tags_cache_error(self, original_error=None):
|
||||||
"""Handle SQLite errors by trying to recreate cache, falling back to dict if needed"""
|
"""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):
|
if isinstance(getattr(self, "TAGS_CACHE", None), dict):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -199,8 +203,6 @@ class RepoMap:
|
||||||
f"Unable to use tags cache at {path}, falling back to memory cache"
|
f"Unable to use tags cache at {path}, falling back to memory cache"
|
||||||
)
|
)
|
||||||
if self.verbose:
|
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.io.tool_warning(f"Cache recreation error: {str(e)}")
|
||||||
|
|
||||||
self.TAGS_CACHE = dict()
|
self.TAGS_CACHE = dict()
|
||||||
|
@ -237,8 +239,8 @@ class RepoMap:
|
||||||
if val is not None and val.get("mtime") == file_mtime:
|
if val is not None and val.get("mtime") == file_mtime:
|
||||||
try:
|
try:
|
||||||
return self.TAGS_CACHE[cache_key]["data"]
|
return self.TAGS_CACHE[cache_key]["data"]
|
||||||
except SQLITE_ERRORS:
|
except SQLITE_ERRORS as e:
|
||||||
self.tags_cache_error()
|
self.tags_cache_error(e)
|
||||||
return self.TAGS_CACHE[cache_key]["data"]
|
return self.TAGS_CACHE[cache_key]["data"]
|
||||||
|
|
||||||
# miss!
|
# miss!
|
||||||
|
@ -248,8 +250,8 @@ class RepoMap:
|
||||||
try:
|
try:
|
||||||
self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data}
|
self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data}
|
||||||
self.save_tags_cache()
|
self.save_tags_cache()
|
||||||
except SQLITE_ERRORS:
|
except SQLITE_ERRORS as e:
|
||||||
self.tags_cache_error()
|
self.tags_cache_error(e)
|
||||||
self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data}
|
self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
@ -352,8 +354,8 @@ class RepoMap:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cache_size = len(self.TAGS_CACHE)
|
cache_size = len(self.TAGS_CACHE)
|
||||||
except SQLITE_ERRORS:
|
except SQLITE_ERRORS as e:
|
||||||
self.tags_cache_error()
|
self.tags_cache_error(e)
|
||||||
cache_size = len(self.TAGS_CACHE)
|
cache_size = len(self.TAGS_CACHE)
|
||||||
|
|
||||||
if len(fnames) - cache_size > 100:
|
if len(fnames) - cache_size > 100:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue