diff --git a/src/dfx-core/src/config/directories.rs b/src/dfx-core/src/config/directories.rs index 8553de3ae6..7c928637ac 100644 --- a/src/dfx-core/src/config/directories.rs +++ b/src/dfx-core/src/config/directories.rs @@ -3,15 +3,15 @@ use crate::error::config::ConfigError::{ DetermineConfigDirectoryFailed, DetermineSharedNetworkDirectoryFailed, EnsureConfigDirectoryExistsFailed, }; -use crate::error::foundation::FoundationError; -use crate::error::foundation::FoundationError::NoHomeInEnvironment; +use crate::error::get_user_home::GetUserHomeError; +use crate::error::get_user_home::GetUserHomeError::NoHomeInEnvironment; #[cfg(not(windows))] use crate::foundation::get_user_home; use crate::fs::composite::ensure_dir_exists; use directories_next::ProjectDirs; use std::path::PathBuf; -pub fn project_dirs() -> Result<&'static ProjectDirs, FoundationError> { +pub fn project_dirs() -> Result<&'static ProjectDirs, GetUserHomeError> { lazy_static::lazy_static! { static ref DIRS: Option = ProjectDirs::from("org", "dfinity", "dfx"); } diff --git a/src/dfx-core/src/error/cache.rs b/src/dfx-core/src/error/cache.rs index 6b2f3a099c..ef24108060 100644 --- a/src/dfx-core/src/error/cache.rs +++ b/src/dfx-core/src/error/cache.rs @@ -2,12 +2,17 @@ use super::{ archive::ArchiveError, fs::FsError, structured_file::StructuredFileError, unified_io::UnifiedIoError, }; +use crate::error::get_current_exe::GetCurrentExeError; +use crate::error::get_user_home::GetUserHomeError; use thiserror::Error; #[derive(Error, Debug)] pub enum CacheError { #[error(transparent)] - FoundationError(#[from] crate::error::foundation::FoundationError), + GetCurrentExeError(#[from] GetCurrentExeError), + + #[error(transparent)] + GetUserHomeError(#[from] GetUserHomeError), #[error(transparent)] UnifiedIo(#[from] crate::error::unified_io::UnifiedIoError), diff --git a/src/dfx-core/src/error/config.rs b/src/dfx-core/src/error/config.rs index 8ca2312784..1121332e42 100644 --- a/src/dfx-core/src/error/config.rs +++ b/src/dfx-core/src/error/config.rs @@ -1,5 +1,5 @@ -use crate::error::foundation::FoundationError; use crate::error::fs::FsError; +use crate::error::get_user_home::GetUserHomeError; use thiserror::Error; #[derive(Error, Debug)] @@ -8,8 +8,8 @@ pub enum ConfigError { EnsureConfigDirectoryExistsFailed(FsError), #[error("Failed to determine config directory path: {0}")] - DetermineConfigDirectoryFailed(FoundationError), + DetermineConfigDirectoryFailed(GetUserHomeError), #[error("Failed to determine shared network data directory: {0}")] - DetermineSharedNetworkDirectoryFailed(FoundationError), + DetermineSharedNetworkDirectoryFailed(GetUserHomeError), } diff --git a/src/dfx-core/src/error/foundation.rs b/src/dfx-core/src/error/get_current_exe.rs similarity index 53% rename from src/dfx-core/src/error/foundation.rs rename to src/dfx-core/src/error/get_current_exe.rs index 0669640d2b..cf74d7d4a4 100644 --- a/src/dfx-core/src/error/foundation.rs +++ b/src/dfx-core/src/error/get_current_exe.rs @@ -1,10 +1,7 @@ use thiserror::Error; #[derive(Error, Debug)] -pub enum FoundationError { - #[error("Cannot find home directory (no HOME environment variable).")] - NoHomeInEnvironment(), - +pub enum GetCurrentExeError { #[error("Failed to identify currently running executable: {0}")] NoCurrentExe(std::io::Error), } diff --git a/src/dfx-core/src/error/get_user_home.rs b/src/dfx-core/src/error/get_user_home.rs new file mode 100644 index 0000000000..7ac0ca2fb5 --- /dev/null +++ b/src/dfx-core/src/error/get_user_home.rs @@ -0,0 +1,7 @@ +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum GetUserHomeError { + #[error("Cannot find home directory (no HOME environment variable).")] + NoHomeInEnvironment(), +} diff --git a/src/dfx-core/src/error/identity/get_legacy_credentials_pem_path.rs b/src/dfx-core/src/error/identity/get_legacy_credentials_pem_path.rs index 731c2a2edc..9d9ed36c84 100644 --- a/src/dfx-core/src/error/identity/get_legacy_credentials_pem_path.rs +++ b/src/dfx-core/src/error/identity/get_legacy_credentials_pem_path.rs @@ -1,8 +1,8 @@ -use crate::error::foundation::FoundationError; +use crate::error::get_user_home::GetUserHomeError; use thiserror::Error; #[derive(Error, Debug)] pub enum GetLegacyCredentialsPemPathError { #[error("Failed to get legacy pem path: {0}")] - GetLegacyPemPathFailed(FoundationError), + GetLegacyPemPathFailed(GetUserHomeError), } diff --git a/src/dfx-core/src/error/mod.rs b/src/dfx-core/src/error/mod.rs index 22f44a4afa..6cd3a42441 100644 --- a/src/dfx-core/src/error/mod.rs +++ b/src/dfx-core/src/error/mod.rs @@ -7,8 +7,9 @@ pub mod config; pub mod dfx_config; pub mod encryption; pub mod extension; -pub mod foundation; pub mod fs; +pub mod get_current_exe; +pub mod get_user_home; pub mod identity; pub mod keyring; pub mod load_dfx_config; diff --git a/src/dfx-core/src/foundation/mod.rs b/src/dfx-core/src/foundation/mod.rs index bf191c04ec..23f9bd577f 100644 --- a/src/dfx-core/src/foundation/mod.rs +++ b/src/dfx-core/src/foundation/mod.rs @@ -1,12 +1,14 @@ -use crate::error::foundation::FoundationError; -use crate::error::foundation::FoundationError::NoHomeInEnvironment; +use crate::error::get_current_exe::GetCurrentExeError; +use crate::error::get_current_exe::GetCurrentExeError::NoCurrentExe; +use crate::error::get_user_home::GetUserHomeError; +use crate::error::get_user_home::GetUserHomeError::NoHomeInEnvironment; use std::ffi::OsString; use std::path::PathBuf; -pub fn get_user_home() -> Result { +pub fn get_user_home() -> Result { std::env::var_os("HOME").ok_or(NoHomeInEnvironment()) } -pub fn get_current_exe() -> Result { - std::env::current_exe().map_err(FoundationError::NoCurrentExe) +pub fn get_current_exe() -> Result { + std::env::current_exe().map_err(NoCurrentExe) }