feat(errors): preserve jj-emitted errors when loading config
Some checks failed
Publish Docker Images / coverage-and-sonar (push) Failing after 16m33s
Some checks failed
Publish Docker Images / coverage-and-sonar (push) Failing after 16m33s
This commit is contained in:
@@ -18,8 +18,8 @@ pub enum Error {
|
||||
RepositoryLocked,
|
||||
#[error("Could not get current directory")]
|
||||
FailedGettingCurrentDir,
|
||||
#[error("Could not load Jujutsu configuration")]
|
||||
FailedReadingConfig,
|
||||
#[error("Could not load Jujutsu configuration: {context}")]
|
||||
FailedReadingConfig { context: String },
|
||||
// Application errors
|
||||
#[error("Operation cancelled by user")]
|
||||
Cancelled,
|
||||
|
||||
@@ -41,16 +41,22 @@ impl JjLib {
|
||||
let mut config = StackedConfig::with_defaults();
|
||||
for path in Self::user_config_paths() {
|
||||
if path.is_dir() {
|
||||
config
|
||||
.load_dir(ConfigSource::User, &path)
|
||||
.map_err(|_| Error::FailedReadingConfig)?;
|
||||
config.load_dir(ConfigSource::User, &path).map_err(|e| {
|
||||
Error::FailedReadingConfig {
|
||||
context: e.to_string(),
|
||||
}
|
||||
})?;
|
||||
} else if path.exists() {
|
||||
config
|
||||
.load_file(ConfigSource::User, path)
|
||||
.map_err(|_| Error::FailedReadingConfig)?;
|
||||
config.load_file(ConfigSource::User, path).map_err(|e| {
|
||||
Error::FailedReadingConfig {
|
||||
context: e.to_string(),
|
||||
}
|
||||
})?;
|
||||
}
|
||||
}
|
||||
UserSettings::from_config(config).map_err(|_| Error::FailedReadingConfig)
|
||||
UserSettings::from_config(config).map_err(|e| Error::FailedReadingConfig {
|
||||
context: e.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Resolves user config file paths following the same logic as the jj CLI:
|
||||
|
||||
@@ -21,7 +21,7 @@ fn error_to_exit_code(error: &Error) -> i32 {
|
||||
Error::InvalidCommitMessage(_) => EXIT_ERROR,
|
||||
Error::NonInteractive => EXIT_ERROR,
|
||||
Error::FailedGettingCurrentDir => EXIT_ERROR,
|
||||
Error::FailedReadingConfig => EXIT_ERROR,
|
||||
Error::FailedReadingConfig { .. } => EXIT_ERROR,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ fn test_all_error_variants() {
|
||||
};
|
||||
let _repo_locked = Error::RepositoryLocked;
|
||||
let _failed_dir = Error::FailedGettingCurrentDir;
|
||||
let _failed_config = Error::FailedReadingConfig;
|
||||
let _failed_config = Error::FailedReadingConfig {
|
||||
context: "test".to_string(),
|
||||
};
|
||||
|
||||
// Application errors
|
||||
let cancelled = Error::Cancelled;
|
||||
|
||||
Reference in New Issue
Block a user