-
Notifications
You must be signed in to change notification settings - Fork 63
fix: add robust handling for getting nodes or edges in kuzudb #124
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
Conversation
Summary of ChangesHello @ChenZiHong-Gavin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the robustness and error handling within the Kuzu graph database storage layer. It focuses on making data retrieval more resilient to malformed or unexpected data formats by implementing comprehensive JSON decoding error checks. Additionally, the changes enhance the database cleanup process, ensuring that the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request significantly improves the robustness of KuzuDB operations by adding comprehensive error handling for JSON decoding when retrieving node and edge data. It also enhances the drop method to handle various file system object types more gracefully. The changes are well-structured and address potential issues with malformed data or unexpected file paths. A consistent improvement would be to replace print statements with proper logging calls for better error tracking and system monitoring.
| try: | ||
| return json.loads(data_str) | ||
| except json.JSONDecodeError as e: | ||
| print(f"Error decoding JSON for node {node_id}: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using print for error messages is generally not recommended in production code. It's better to use a logging framework (e.g., Python's logging module) to allow for configurable log levels, output destinations, and structured logging. This improves maintainability and debugging capabilities.
| print(f"Error decoding JSON for node {node_id}: {e}") | |
| logging.error(f"Error decoding JSON for node {node_id}: {e}") |
| try: | ||
| data = json.loads(data_str) if data_str and data_str.strip() else {} | ||
| except json.JSONDecodeError as e: | ||
| print(f"Error decoding JSON for node {node_id}: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better error tracking and system monitoring, print statements should be replaced with a proper logging mechanism. This allows for more flexible handling of error messages.
| print(f"Error decoding JSON for node {node_id}: {e}") | |
| logging.error(f"Error decoding JSON for node {node_id}: {e}") |
| print( | ||
| f"Error decoding JSON for edge {source_node_id}->{target_node_id}: {e}" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replacing print with a logging call is a best practice for handling errors in a way that can be configured and monitored. This ensures that error messages are handled consistently across the application.
| print( | |
| f"Error decoding JSON for edge {source_node_id}->{target_node_id}: {e}" | |
| ) | |
| logging.error( | |
| f"Error decoding JSON for edge {source_node_id}->{target_node_id}: {e}" | |
| ) |
| try: | ||
| data = json.loads(data_str) if data_str and data_str.strip() else {} | ||
| except json.JSONDecodeError as e: | ||
| print(f"Error decoding JSON for edge {src}->{dst}: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's recommended to use a logging framework instead of print for error messages. This provides more control over log output and severity, which is crucial for debugging and operational insights.
| print(f"Error decoding JSON for edge {src}->{dst}: {e}") | |
| logging.error(f"Error decoding JSON for edge {src}->{dst}: {e}") |
| try: | ||
| data = json.loads(data_str) if data_str and data_str.strip() else {} | ||
| except json.JSONDecodeError as e: | ||
| print(f"Error decoding JSON for edge {src}->{dst}: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistent error handling and better observability, print statements should be replaced with calls to a logging utility. This allows for centralized management of log messages.
| print(f"Error decoding JSON for edge {src}->{dst}: {e}") | |
| logging.error(f"Error decoding JSON for edge {src}->{dst}: {e}") |
| if os.path.isdir(self.db_path): | ||
| shutil.rmtree(self.db_path) | ||
| print(f"Dropped KuzuDB at {self.db_path}") | ||
| print(f"Dropped KuzuDB directory at {self.db_path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Informational messages like this should ideally use logging.info instead of print. This allows for better control over log verbosity and integration with monitoring systems.
| print(f"Dropped KuzuDB directory at {self.db_path}") | |
| logging.info(f"Dropped KuzuDB directory at {self.db_path}") |
| print(f"Dropped KuzuDB directory at {self.db_path}") | ||
| elif os.path.isfile(self.db_path): | ||
| os.remove(self.db_path) | ||
| print(f"Dropped KuzuDB file at {self.db_path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| print(f"Dropped KuzuDB file at {self.db_path}") | ||
| elif os.path.exists(self.db_path): | ||
| os.unlink(self.db_path) | ||
| print(f"Dropped KuzuDB path at {self.db_path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| os.unlink(self.db_path) | ||
| print(f"Dropped KuzuDB path at {self.db_path}") | ||
| else: | ||
| print(f"Database path {self.db_path} does not exist") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For situations where a path does not exist, logging.warning is more appropriate than print. This highlights a potential issue without being a critical error, and integrates well with logging systems.
| print(f"Database path {self.db_path} does not exist") | |
| logging.warning(f"Database path {self.db_path} does not exist") |
…to fix/fix-kuzudb-error
This PR enhances error handling and input validation in the Kuzu graph database storage layer.