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

Handle None for environments that have data directories #160

Open
ryardley opened this issue Oct 28, 2024 · 0 comments
Open

Handle None for environments that have data directories #160

ryardley opened this issue Oct 28, 2024 · 0 comments
Labels
bug Something isn't working Ciphernode Related to the ciphernode package

Comments

@ryardley
Copy link
Contributor

          _:warning: Potential issue_

Handle potential None values when retrieving configuration directories

The code uses unwrap() on dirs::config_dir() and dirs::data_local_dir(), which will cause the program to panic if these functions return None. This can happen in environments where the configuration or data directories are not set. Consider handling the None case to provide a more robust implementation.

Apply this diff to handle potential None values:

-    pub fn config_dir() -> PathBuf {
-        dirs::config_dir().unwrap().join("enclave")
+    pub fn config_dir() -> Option<PathBuf> {
+        dirs::config_dir().map(|dir| dir.join("enclave"))
     }

-    pub fn data_dir() -> PathBuf {
-        dirs::data_local_dir().unwrap().join("enclave")
+    pub fn data_dir() -> Option<PathBuf> {
+        dirs::data_local_dir().map(|dir| dir.join("enclave"))
     }

You'll need to handle the change in return types from PathBuf to Option<PathBuf> throughout your codebase to ensure proper error handling if the directories are unavailable.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    pub fn config_dir() -> Option<PathBuf> {
        dirs::config_dir().map(|dir| dir.join("enclave"))
    }

    pub fn data_dir() -> Option<PathBuf> {
        dirs::data_local_dir().map(|dir| dir.join("enclave"))
    }

Originally posted by @coderabbitai[bot] in #156 (comment)

@ryardley ryardley added bug Something isn't working Ciphernode Related to the ciphernode package labels Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Ciphernode Related to the ciphernode package
Projects
None yet
Development

No branches or pull requests

1 participant