Skip to content

Commit

Permalink
Move try-catch up a level for error parsing file (#24)
Browse files Browse the repository at this point in the history
* Move try-catch up a level

* Bump version
  • Loading branch information
shruti222patel authored Aug 22, 2023
1 parent 1b50287 commit d1c609f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Binary file removed .repo_gpt/code_embeddings.pkl
Binary file not shown.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "repo-gpt"
version = "0.1.4"
version = "0.1.5"
description = "Search your code repository using GPT3.5 or GPT4."
authors = ["Shruti Patel <[email protected]>"]
license = "Apache License 2.0"
Expand Down
11 changes: 7 additions & 4 deletions src/repo_gpt/code_manager/code_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ def extract_functions_from_file(
handler = self.get_handler(filepath)
code_blocks = []
if handler:
code_blocks = handler().extract_code(filepath)
for code in code_blocks:
code.filepath = filepath
code.file_checksum = file_checksum
try:
code_blocks = handler().extract_code(filepath)
for code in code_blocks:
code.filepath = filepath
code.file_checksum = file_checksum
except Exception as e:
logger.error(f"Error extracting code from {filepath}: {e}")

return code_blocks
9 changes: 3 additions & 6 deletions src/repo_gpt/file_handler/generic_code_file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ def get_class_name(self, class_node):

def extract_code(self, filepath: Path) -> List[ParsedCode]:
with open(filepath, "r", encoding="utf-8") as source_code:
try:
code = source_code.read()
tree = self.parser.parse(bytes(code, "utf8"))
return self.parse_tree(tree)
except Exception as e:
print(f"Failed to parse file {filepath}: {e}")
code = source_code.read()
tree = self.parser.parse(bytes(code, "utf8"))
return self.parse_tree(tree)

def parse_tree(self, tree) -> List[ParsedCode]:
parsed_nodes = []
Expand Down

0 comments on commit d1c609f

Please sign in to comment.