fix: handle exceptions during index loading and recreate cache if necessary in aider/help.py

This commit is contained in:
Paul Gauthier (aider) 2024-09-27 12:22:09 -07:00
parent a230fa10b3
commit cb1f6f2e3a

View file

@ -58,6 +58,9 @@ def fname_to_url(filepath):
return docid
import json
import shutil
def get_index():
from llama_index.core import (
Document,
@ -69,12 +72,23 @@ def get_index():
dname = Path.home() / ".aider" / "caches" / ("help." + __version__)
index = None
if dname.exists():
try:
storage_context = StorageContext.from_defaults(
persist_dir=dname,
)
index = load_index_from_storage(storage_context)
except (OSError, json.JSONDecodeError):
shutil.rmtree(dname)
pass
storage_context = StorageContext.from_defaults(
persist_dir=dname,
)
index = load_index_from_storage(storage_context)
else:
if index is None:
parser = MarkdownNodeParser()
nodes = []