mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 18:54:59 +00:00
fix: Refactor code to handle exceptions more gracefully
This commit is contained in:
parent
6ab1fdfe36
commit
3b9f561956
1 changed files with 25 additions and 31 deletions
|
@ -74,45 +74,39 @@ def get_index():
|
||||||
dname = Path.home() / ".aider" / "caches" / ("help." + __version__)
|
dname = Path.home() / ".aider" / "caches" / ("help." + __version__)
|
||||||
|
|
||||||
index = None
|
index = None
|
||||||
|
try:
|
||||||
if dname.exists():
|
if dname.exists():
|
||||||
try:
|
|
||||||
storage_context = StorageContext.from_defaults(
|
storage_context = StorageContext.from_defaults(
|
||||||
persist_dir=dname,
|
persist_dir=dname,
|
||||||
)
|
)
|
||||||
index = load_index_from_storage(storage_context)
|
index = load_index_from_storage(storage_context)
|
||||||
except (OSError, json.JSONDecodeError):
|
except (OSError, json.JSONDecodeError):
|
||||||
shutil.rmtree(dname)
|
shutil.rmtree(dname)
|
||||||
pass
|
|
||||||
storage_context = StorageContext.from_defaults(
|
if index is None:
|
||||||
persist_dir=dname,
|
|
||||||
)
|
|
||||||
index = load_index_from_storage(storage_context)
|
|
||||||
else:
|
|
||||||
if index is None:
|
|
||||||
parser = MarkdownNodeParser()
|
parser = MarkdownNodeParser()
|
||||||
|
|
||||||
nodes = []
|
nodes = []
|
||||||
for fname in get_package_files():
|
for fname in get_package_files():
|
||||||
fname = Path(fname)
|
fname = Path(fname)
|
||||||
if any(fname.match(pat) for pat in exclude_website_pats):
|
if any(fname.match(pat) for pat in exclude_website_pats):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
doc = Document(
|
doc = Document(
|
||||||
text=importlib_resources.files("aider.website")
|
text=importlib_resources.files("aider.website")
|
||||||
.joinpath(fname)
|
.joinpath(fname)
|
||||||
.read_text(encoding="utf-8"),
|
.read_text(encoding="utf-8"),
|
||||||
metadata=dict(
|
metadata=dict(
|
||||||
filename=fname.name,
|
filename=fname.name,
|
||||||
extension=fname.suffix,
|
extension=fname.suffix,
|
||||||
url=fname_to_url(str(fname)),
|
url=fname_to_url(str(fname)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
nodes += parser.get_nodes_from_documents([doc])
|
nodes += parser.get_nodes_from_documents([doc])
|
||||||
|
|
||||||
index = VectorStoreIndex(nodes, show_progress=True)
|
index = VectorStoreIndex(nodes, show_progress=True)
|
||||||
dname.parent.mkdir(parents=True, exist_ok=True)
|
dname.parent.mkdir(parents=True, exist_ok=True)
|
||||||
index.storage_context.persist(dname)
|
index.storage_context.persist(dname)
|
||||||
|
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue