mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
feat: add auto-recovery for corrupted tags cache
This commit is contained in:
parent
e25a46c892
commit
7f027ff6e5
1 changed files with 33 additions and 5 deletions
|
@ -167,11 +167,39 @@ class RepoMap:
|
||||||
return fname
|
return fname
|
||||||
|
|
||||||
def tags_cache_error(self):
|
def tags_cache_error(self):
|
||||||
"""Handle SQLite errors by falling back to dict-based cache"""
|
"""Handle SQLite errors by trying to recreate cache, falling back to dict if needed"""
|
||||||
if isinstance(self.TAGS_CACHE, Cache):
|
if not isinstance(self.TAGS_CACHE, Cache):
|
||||||
path = Path(self.root) / self.TAGS_CACHE_DIR
|
return
|
||||||
self.io.tool_warning(f"Unable to use tags cache, delete {path} to resolve.")
|
|
||||||
self.TAGS_CACHE = dict()
|
path = Path(self.root) / self.TAGS_CACHE_DIR
|
||||||
|
|
||||||
|
# Try to recreate the cache
|
||||||
|
try:
|
||||||
|
# Delete existing cache dir
|
||||||
|
if path.exists():
|
||||||
|
import shutil
|
||||||
|
shutil.rmtree(path)
|
||||||
|
|
||||||
|
# Try to create new cache
|
||||||
|
new_cache = Cache(path)
|
||||||
|
|
||||||
|
# Test that it works
|
||||||
|
test_key = "test"
|
||||||
|
new_cache[test_key] = "test"
|
||||||
|
_ = new_cache[test_key]
|
||||||
|
del new_cache[test_key]
|
||||||
|
|
||||||
|
# If we got here, the new cache works
|
||||||
|
self.TAGS_CACHE = new_cache
|
||||||
|
return
|
||||||
|
|
||||||
|
except (SQLITE_ERRORS, OSError) as e:
|
||||||
|
# If anything goes wrong, warn and fall back to dict
|
||||||
|
self.io.tool_warning(f"Unable to use tags cache at {path}, falling back to memory cache")
|
||||||
|
if self.verbose:
|
||||||
|
self.io.tool_warning(f"Cache error: {str(e)}")
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue