From a588965b942409420fa7d42fde153b7cc8437fd2 Mon Sep 17 00:00:00 2001 From: Arya Date: Tue, 20 Jun 2023 01:11:23 -0400 Subject: [PATCH] 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 --- zebrad/src/application.rs | 4 +++- zebrad/src/commands.rs | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/zebrad/src/application.rs b/zebrad/src/application.rs index 90adeb08..68134f7d 100644 --- a/zebrad/src/application.rs +++ b/zebrad/src/application.rs @@ -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); diff --git a/zebrad/src/commands.rs b/zebrad/src/commands.rs index 2f005f79..806ac360 100644 --- a/zebrad/src/commands.rs +++ b/zebrad/src/commands.rs @@ -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 {