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

Refactor FileRepository to handle non-existent directories #176

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

xbotter
Copy link
Contributor

@xbotter xbotter commented Oct 18, 2023

Summary:
This pull request refactors the FileRepository class in the BotSharp.Core project to handle non-existent directories. Previously, the code assumed that the required directories always existed, leading to potential errors when the directories were missing. This refactor adds checks to ensure that the directories exist before attempting to read files from them.

Changes Made:

  • Added checks for the existence of directories before reading files in the GetUser, GetAgent, GetUserAgent, and GetConversation methods of the FileRepository class.
  • If a directory does not exist, the corresponding method now returns an empty collection instead of throwing an exception.
  • Improved error handling and added appropriate comments to clarify the code.

Detailed List of Changes:

  • In the GetUser method:
    • Added a check to ensure that the "users" directory exists before attempting to read user files.
    • If the directory does not exist, an empty collection is returned.
  • In the GetAgent method:
    • Added a check to ensure that the agent's data directory exists before attempting to read agent files.
    • If the directory does not exist, an empty collection is returned.
  • In the GetUserAgent method:
    • Added a check to ensure that the "users" directory exists before attempting to read user agent files.
    • If the directory does not exist, an empty collection is returned.
  • In the GetConversation method:
    • Added a check to ensure that the conversation's data directory exists before attempting to read conversation files.
    • If the directory does not exist, an empty collection is returned.

These changes improve the robustness of the FileRepository class by handling cases where the required directories are missing.

- The FileRepository class in the BotSharp.Core.Repository namespace has been updated to handle cases where the "users" and agent directories are missing.
- Previously, the code would throw an exception if the directories were not found, but now it checks for their existence before attempting to read files from them.
- This change ensures that the repository can gracefully handle missing directories and continue execution without errors.
- The update includes changes to the GetUserAgents, GetAgents, and GetConversations methods, as well as the UpdateAgent, UpdateInstruction, and UpdateFunctions methods.
- Additionally, the code now properly checks for the existence of the "agents.json" file before attempting to read from it.
- These changes improve the robustness and reliability of the FileRepository class.
@Oceania2018 Oceania2018 merged commit 09ea77b into SciSharp:master Oct 18, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants