From 46bc9528a51316dc455fc518de70f39713560d16 Mon Sep 17 00:00:00 2001 From: ByteOtter Date: Thu, 7 Sep 2023 17:11:43 +0200 Subject: [PATCH] graceful exit for empty config file --- src/configuration/config_parser.rs | 6 ++++-- src/main.rs | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/configuration/config_parser.rs b/src/configuration/config_parser.rs index 5206a92..c1a8ce4 100644 --- a/src/configuration/config_parser.rs +++ b/src/configuration/config_parser.rs @@ -15,6 +15,7 @@ use serde::Deserialize; use std::fs::File; use std::io::prelude::*; use std::path::Path; +use std::process; use std::{fs, path::PathBuf}; use toml::Value; @@ -86,10 +87,11 @@ pub fn set_up_configuration( } if uri.is_none() || token.is_none() { - panic!( + println!( "x1b[31mFATAL:x1b[0m No configuration parameters found in CLI while using an empty config file!\n Please enter valid configuration parameters in the configuration file or provide them via the CLI." - ) + ); + process::exit(1); } conf_data = ConfigData::read_config_file(); diff --git a/src/main.rs b/src/main.rs index 73f9acf..d02805b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,6 +47,7 @@ fn main() { let config: ConfigData = match set_up_configuration(args.uri, args.token) { Ok(conf) => conf, Err(err) => { + // This behavior will change panic!("{}", err) } };