From ea04b6f151833fa726b3ad1a49761cc840dc75f1 Mon Sep 17 00:00:00 2001 From: "Helmut K. C. Tessarek" Date: Sun, 17 Mar 2024 14:53:41 -0400 Subject: [PATCH] refactor: replace panic with a graceful exit (#4402) * refactor: replace panic with a graceful exit * fix: clippy errors * fix: typo * Update src/main.rs Co-authored-by: Stefan Melmuk <509385+stefan0xC@users.noreply.github.com> --------- Co-authored-by: Stefan Melmuk <509385+stefan0xC@users.noreply.github.com> --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 285dc33a..e3b29383 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,11 @@ async fn main() -> Result<(), Error> { launch_info(); use log::LevelFilter as LF; - let level = LF::from_str(&CONFIG.log_level()).expect("Valid log level"); + let level = LF::from_str(&CONFIG.log_level()).unwrap_or_else(|_| { + let valid_log_levels = LF::iter().map(|lvl| lvl.as_str().to_lowercase()).collect::>().join(", "); + println!("Log level must be one of the following: {valid_log_levels}"); + exit(1); + }); init_logging(level).ok(); let extra_debug = matches!(level, LF::Trace | LF::Debug);