change(commands): Ignore error from loading config if running the 'generate' or 'download' commands (#7014)

* ignore error when reading config for generate cmd

* Adds comments.

* ignore load config errs for download cmd too

* Fix comment wording

---------

Co-authored-by: teor <teor@riseup.net>
This commit is contained in:
Arya 2023-06-20 01:11:23 -04:00 committed by GitHub
parent cd8dddffe5
commit a588965b94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -241,10 +241,12 @@ impl Application for ZebradApp {
let mut components = self.framework_components(command)?;
// Load config *after* framework components so that we can
// report an error to the terminal if it occurs.
// report an error to the terminal if it occurs (unless used with a command that doesn't need the config).
let config = match command.config_path() {
Some(path) => match self.load_config(&path) {
Ok(config) => config,
// Ignore errors loading the config for some commands.
Err(_e) if command.cmd().should_ignore_load_config_error() => Default::default(),
Err(e) => {
status_err!("Zebra could not parse the provided config file. This might mean you are using a deprecated format of the file. You can generate a valid config by running \"zebrad generate\", and diff it against yours to examine any format inconsistencies.");
return Err(e);

View File

@ -87,6 +87,12 @@ impl ZebradCmd {
"debug"
}
}
/// Returns true if this command should ignore errors when
/// attempting to load a config file.
pub(crate) fn should_ignore_load_config_error(&self) -> bool {
matches!(self, ZebradCmd::Generate(_) | ZebradCmd::Download(_))
}
}
impl Runnable for ZebradCmd {