feat(errors): preserve jj-emitted errors when loading config
This commit is contained in:
@@ -18,8 +18,8 @@ pub enum Error {
|
|||||||
RepositoryLocked,
|
RepositoryLocked,
|
||||||
#[error("Could not get current directory")]
|
#[error("Could not get current directory")]
|
||||||
FailedGettingCurrentDir,
|
FailedGettingCurrentDir,
|
||||||
#[error("Could not load Jujutsu configuration")]
|
#[error("Could not load Jujutsu configuration: {context}")]
|
||||||
FailedReadingConfig,
|
FailedReadingConfig { context: String },
|
||||||
// Application errors
|
// Application errors
|
||||||
#[error("Operation cancelled by user")]
|
#[error("Operation cancelled by user")]
|
||||||
Cancelled,
|
Cancelled,
|
||||||
|
|||||||
@@ -41,16 +41,22 @@ impl JjLib {
|
|||||||
let mut config = StackedConfig::with_defaults();
|
let mut config = StackedConfig::with_defaults();
|
||||||
for path in Self::user_config_paths() {
|
for path in Self::user_config_paths() {
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
config
|
config.load_dir(ConfigSource::User, &path).map_err(|e| {
|
||||||
.load_dir(ConfigSource::User, &path)
|
Error::FailedReadingConfig {
|
||||||
.map_err(|_| Error::FailedReadingConfig)?;
|
context: e.to_string(),
|
||||||
|
}
|
||||||
|
})?;
|
||||||
} else if path.exists() {
|
} else if path.exists() {
|
||||||
config
|
config.load_file(ConfigSource::User, path).map_err(|e| {
|
||||||
.load_file(ConfigSource::User, path)
|
Error::FailedReadingConfig {
|
||||||
.map_err(|_| 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:
|
/// 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::InvalidCommitMessage(_) => EXIT_ERROR,
|
||||||
Error::NonInteractive => EXIT_ERROR,
|
Error::NonInteractive => EXIT_ERROR,
|
||||||
Error::FailedGettingCurrentDir => 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 _repo_locked = Error::RepositoryLocked;
|
||||||
let _failed_dir = Error::FailedGettingCurrentDir;
|
let _failed_dir = Error::FailedGettingCurrentDir;
|
||||||
let _failed_config = Error::FailedReadingConfig;
|
let _failed_config = Error::FailedReadingConfig {
|
||||||
|
context: "test".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
// Application errors
|
// Application errors
|
||||||
let cancelled = Error::Cancelled;
|
let cancelled = Error::Cancelled;
|
||||||
|
|||||||
Reference in New Issue
Block a user