Browse Source

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 <[email protected]>

---------

Co-authored-by: Stefan Melmuk <[email protected]>
Helmut K. C. Tessarek 1 year ago
parent
commit
ea04b6f151
1 changed files with 5 additions and 1 deletions
  1. 5 1
      src/main.rs

+ 5 - 1
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::<Vec<String>>().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);