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.
This commit is contained in:
Ignotus Peverell 2018-05-22 18:50:09 +01:00
parent 7281dc9473
commit 90746537a3
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211
2 changed files with 6 additions and 12 deletions

View file

@ -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<GlobalConfig, ConfigError> {
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<GlobalConfig, ConfigError> {
fn read_config(mut self) -> Result<GlobalConfig, ConfigError> {
let mut file = File::open(self.config_file_path.as_mut().unwrap())?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;

View file

@ -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