From 90746537a36bd7a2db02fb0d31cc633ab008d787 Mon Sep 17 00:00:00 2001 From: Ignotus Peverell Date: Tue, 22 May 2018 18:50:09 +0100 Subject: [PATCH] Server panics when no config file is found Can't do anything useful without config at this point, so we might as well panic rather than confuse people. Minor cleanup of config. --- config/src/config.rs | 13 +++++-------- src/bin/grin.rs | 5 +---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/config/src/config.rs b/config/src/config.rs index 98a1ed258..8db451928 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -89,10 +89,8 @@ impl GlobalConfig { Err(ConfigError::FileNotFoundError(String::from(""))) } - /// Takes the path to a config file, or if NONE, tries - /// to determine a config file based on rules in - /// derive_config_location - + /// Takes the path to a config file, or if NONE, tries to determine a config + /// file based on rules in derive_config_location pub fn new(file_path: Option<&str>) -> Result { let mut return_value = GlobalConfig::default(); if let Some(fp) = file_path { @@ -119,14 +117,13 @@ impl GlobalConfig { ))); } - // Try to parse the config file if it exists - // explode if it does exist but something's wrong - // with it + // Try to parse the config file if it exists explode if it does exist but + // something's wrong with it return_value.read_config() } /// Read config - pub fn read_config(mut self) -> Result { + fn read_config(mut self) -> Result { let mut file = File::open(self.config_file_path.as_mut().unwrap())?; let mut contents = String::new(); file.read_to_string(&mut contents)?; diff --git a/src/bin/grin.rs b/src/bin/grin.rs index a57c55f54..e78a41051 100644 --- a/src/bin/grin.rs +++ b/src/bin/grin.rs @@ -378,10 +378,7 @@ fn server_command(server_args: Option<&ArgMatches>, mut global_config: GlobalCon .chain_type, ); } else { - info!( - LOGGER, - "Starting the Grin server (no configuration file) ..." - ); + panic!("No configuration found."); } // just get defaults from the global config