mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 08:44:59 +00:00
feat: add error handling for SQLite tags cache operations
This commit is contained in:
parent
e9771588e4
commit
68916b1186
1 changed files with 21 additions and 5 deletions
|
@ -166,13 +166,19 @@ class RepoMap:
|
||||||
# Just return the full fname.
|
# Just return the full fname.
|
||||||
return fname
|
return fname
|
||||||
|
|
||||||
|
def tags_cache_error(self):
|
||||||
|
"""Handle SQLite errors by falling back to dict-based cache"""
|
||||||
|
if isinstance(self.TAGS_CACHE, Cache):
|
||||||
|
path = Path(self.root) / self.TAGS_CACHE_DIR
|
||||||
|
self.io.tool_warning(f"Unable to use tags cache, delete {path} to resolve.")
|
||||||
|
self.TAGS_CACHE = dict()
|
||||||
|
|
||||||
def load_tags_cache(self):
|
def load_tags_cache(self):
|
||||||
path = Path(self.root) / self.TAGS_CACHE_DIR
|
path = Path(self.root) / self.TAGS_CACHE_DIR
|
||||||
try:
|
try:
|
||||||
self.TAGS_CACHE = Cache(path)
|
self.TAGS_CACHE = Cache(path)
|
||||||
except SQLITE_ERRORS:
|
except SQLITE_ERRORS:
|
||||||
self.io.tool_warning(f"Unable to use tags cache, delete {path} to resolve.")
|
self.tags_cache_error()
|
||||||
self.TAGS_CACHE = dict()
|
|
||||||
|
|
||||||
def save_tags_cache(self):
|
def save_tags_cache(self):
|
||||||
pass
|
pass
|
||||||
|
@ -190,9 +196,18 @@ class RepoMap:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
cache_key = fname
|
cache_key = fname
|
||||||
val = self.TAGS_CACHE.get(cache_key) # Issue #1308
|
try:
|
||||||
|
val = self.TAGS_CACHE.get(cache_key) # Issue #1308
|
||||||
|
except SQLITE_ERRORS:
|
||||||
|
self.tags_cache_error()
|
||||||
|
val = self.TAGS_CACHE.get(cache_key)
|
||||||
|
|
||||||
if val is not None and val.get("mtime") == file_mtime:
|
if val is not None and val.get("mtime") == file_mtime:
|
||||||
return self.TAGS_CACHE[cache_key]["data"]
|
try:
|
||||||
|
return self.TAGS_CACHE[cache_key]["data"]
|
||||||
|
except SQLITE_ERRORS:
|
||||||
|
self.tags_cache_error()
|
||||||
|
return self.TAGS_CACHE[cache_key]["data"]
|
||||||
|
|
||||||
# miss!
|
# miss!
|
||||||
data = list(self.get_tags_raw(fname, rel_fname))
|
data = list(self.get_tags_raw(fname, rel_fname))
|
||||||
|
@ -202,7 +217,8 @@ class RepoMap:
|
||||||
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:
|
||||||
pass
|
self.tags_cache_error()
|
||||||
|
self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue