Skip to content

Commit

Permalink
feat: Add error handling for ImportError in RepoMap.find_definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
fry69 committed Sep 7, 2024
1 parent 2eae373 commit 8cb08e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion aider/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,13 @@ def validate_environment(self):
# https://github.com/BerriAI/litellm/issues/3190

model = self.name
res = litellm.validate_environment(model)

try:
res = litellm.validate_environment(model)
except ImportError as err:
self.io.tool_error("Error while loading necessary module: {err}")
sys.exit(1)

if res["keys_in_environment"]:
return res
if res["missing_keys"]:
Expand Down
3 changes: 3 additions & 0 deletions aider/repomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ def get_ranked_tags(
ranked = nx.pagerank(G, weight="weight", **pers_args)
except ZeroDivisionError:
return []
except ImportError as err:
self.io.tool_error("Error while loading necessary module: {err}")
sys.exit(1)

# distribute the rank from each source node, across all of its out edges
ranked_definitions = defaultdict(float)
Expand Down
7 changes: 6 additions & 1 deletion aider/sendchat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hashlib
import json
import sys

import backoff

Expand Down Expand Up @@ -83,7 +84,11 @@ def send_completion(

# del kwargs['stream']

res = litellm.completion(**kwargs)
try:
res = litellm.completion(**kwargs)
except ImportError as err:
print("Error while loading necessary module: {err}")
sys.exit(1)

if not stream and CACHE is not None:
CACHE[key] = res
Expand Down

0 comments on commit 8cb08e6

Please sign in to comment.