Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve error handling in function parameter parsing #399

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion babyagi/functionz/core/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def wrapper(*args, **kwargs):
def parse_function_parameters(self, code: str):
"""
Parse the input and output parameters of a given function code.
Returns tuple of (input_params, output_params).
If parsing fails, logs the error and returns empty lists.
"""
try:
# Parse the source code into an AST
Expand Down Expand Up @@ -82,8 +84,14 @@ def parse_function_parameters(self, code: str):
output_params.append({'name': 'output', 'type': 'Any'})

return input_params, output_params
except StopIteration:
logger.error("No function definition found in the provided code")
return [], []
except SyntaxError as e:
logger.error(f"Syntax error in function code: {str(e)}")
return [], []
except Exception as e:
# print(f"Error parsing function parameters: {str(e)}")
logger.error(f"Error parsing function parameters: {str(e)}")
return [], []

def parse_import(self, imp):
Expand Down