From c0250f19040409c69b120d5a9b33c6adc9e6798a Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 22 Nov 2024 11:46:09 +0900 Subject: [PATCH] config: rename jj_cli::config::ConfigError to ConfigEnvError It was confusing because we often refer to config::ConfigError as ConfigError. --- cli/src/cli_util.rs | 3 ++- cli/src/command_error.rs | 5 +++-- cli/src/config.rs | 28 ++++++++++++++-------------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index a445d5620..7f76690a7 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -146,6 +146,7 @@ use crate::complete; use crate::config::new_config_path; use crate::config::AnnotatedValue; use crate::config::CommandNameAndArgs; +use crate::config::ConfigEnvError; use crate::config::ConfigSource; use crate::config::LayeredConfigs; use crate::diff_util; @@ -317,7 +318,7 @@ impl CommandHelper { pub fn resolved_config_values( &self, prefix: &ConfigNamePathBuf, - ) -> Result, crate::config::ConfigError> { + ) -> Result, ConfigEnvError> { self.data.layered_configs.resolved_config_values(prefix) } diff --git a/cli/src/command_error.rs b/cli/src/command_error.rs index 9dc674828..5070895eb 100644 --- a/cli/src/command_error.rs +++ b/cli/src/command_error.rs @@ -56,6 +56,7 @@ use jj_lib::workspace::WorkspaceInitError; use thiserror::Error; use crate::cli_util::short_operation_hash; +use crate::config::ConfigEnvError; use crate::description_util::ParseBulkEditMessageError; use crate::diff_util::DiffRenderError; use crate::formatter::FormatRecorder; @@ -243,8 +244,8 @@ impl From for CommandError { } } -impl From for CommandError { - fn from(err: crate::config::ConfigError) -> Self { +impl From for CommandError { + fn from(err: ConfigEnvError) -> Self { config_error(err) } } diff --git a/cli/src/config.rs b/cli/src/config.rs index 19f44bf13..824ea5b6f 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -74,7 +74,7 @@ pub fn to_toml_value(value: &config::Value) -> Result Result<(), ConfigError> { + pub fn read_user_config(&mut self) -> Result<(), ConfigEnvError> { self.user = existing_config_path()? .map(|path| read_config_path(&path)) .transpose()?; Ok(()) } - pub fn user_config_path(&self) -> Result, ConfigError> { + pub fn user_config_path(&self) -> Result, ConfigEnvError> { existing_config_path() } #[instrument] - pub fn read_repo_config(&mut self, repo_path: &Path) -> Result<(), ConfigError> { + pub fn read_repo_config(&mut self, repo_path: &Path) -> Result<(), ConfigEnvError> { self.repo = Some(read_config_file(&self.repo_config_path(repo_path))?); Ok(()) } @@ -156,7 +156,7 @@ impl LayeredConfigs { repo_path.join("config.toml") } - pub fn parse_config_args(&mut self, toml_strs: &[String]) -> Result<(), ConfigError> { + pub fn parse_config_args(&mut self, toml_strs: &[String]) -> Result<(), ConfigEnvError> { let config = toml_strs .iter() .fold(config::Config::builder(), |builder, s| { @@ -197,7 +197,7 @@ impl LayeredConfigs { pub fn resolved_config_values( &self, filter_prefix: &ConfigNamePathBuf, - ) -> Result, ConfigError> { + ) -> Result, ConfigEnvError> { // Collect annotated values from each config. let mut config_vals = vec![]; for (source, config) in self.sources() { @@ -301,7 +301,7 @@ impl ConfigEnv { } } - fn config_path(self) -> Result { + fn config_path(self) -> Result { if let Some(path) = self.jj_config { // TODO: We should probably support colon-separated (std::env::split_paths) return Ok(ConfigPath::new(Some(PathBuf::from(path)))); @@ -320,7 +320,7 @@ impl ConfigEnv { use ConfigPath::*; match (platform_config_path, home_config_path) { (Existing(platform_config_path), Existing(home_config_path)) => Err( - ConfigError::AmbiguousSource(platform_config_path, home_config_path), + ConfigEnvError::AmbiguousSource(platform_config_path, home_config_path), ), (Existing(path), _) | (_, Existing(path)) => Ok(Existing(path)), (New(path), _) | (_, New(path)) => Ok(New(path)), @@ -328,14 +328,14 @@ impl ConfigEnv { } } - fn existing_config_path(self) -> Result, ConfigError> { + fn existing_config_path(self) -> Result, ConfigEnvError> { match self.config_path()? { ConfigPath::Existing(path) => Ok(Some(path)), _ => Ok(None), } } - fn new_config_path(self) -> Result, ConfigError> { + fn new_config_path(self) -> Result, ConfigEnvError> { match self.config_path()? { ConfigPath::Existing(path) => Ok(Some(path)), ConfigPath::New(path) => { @@ -347,7 +347,7 @@ impl ConfigEnv { } } -pub fn existing_config_path() -> Result, ConfigError> { +pub fn existing_config_path() -> Result, ConfigEnvError> { ConfigEnv::new().existing_config_path() } @@ -356,7 +356,7 @@ pub fn existing_config_path() -> Result, ConfigError> { /// If no config file is found, tries to guess a reasonable new /// location for it. If a path to a new config file is returned, the /// parent directory may be created as a result of this call. -pub fn new_config_path() -> Result, ConfigError> { +pub fn new_config_path() -> Result, ConfigEnvError> { ConfigEnv::new().new_config_path() } @@ -1203,11 +1203,11 @@ mod tests { use assert_matches::assert_matches; assert_matches!( cfg.clone().existing_config_path(), - Err(ConfigError::AmbiguousSource(_, _)) + Err(ConfigEnvError::AmbiguousSource(_, _)) ); assert_matches!( cfg.clone().new_config_path(), - Err(ConfigError::AmbiguousSource(_, _)) + Err(ConfigEnvError::AmbiguousSource(_, _)) ); Ok(()) }