diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-01-02 15:51:27 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-01-02 16:13:39 +0100 |
commit | f1694b77a64684efac5c637d2036eb087082c91d (patch) | |
tree | 1e32e66994dff12472047d26fc5df01e800ad0ba | |
parent | ca76f067282c3c3750c3287b914fd7d803db436e (diff) |
Make main() return error
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/main.rs | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/main.rs b/src/main.rs index f03eff4..344a971 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,6 @@ use std::collections::HashMap; use std::fs::File; use std::path::PathBuf; use std::io::{BufReader, BufRead}; -use std::process::exit; use std::str::FromStr; use clap::{App, Arg}; @@ -211,7 +210,7 @@ fn hash_map_iter(h : HashMap<&String, (&LogItem, Vec<(String, String)>)>, d_from } -fn main() { +fn main() -> Result<()> { let matches = App::new("aklog-server") .version("0.1.0") @@ -255,30 +254,23 @@ fn main() { debug!("Initialized logger"); let config_file = matches.value_of("config").unwrap(); - let config = match Config::load(PathBuf::from(String::from(config_file))) { - Ok(c) => c, - Err(e) => { - error!("{}", e); - exit(1); - }, - }; + let config = Config::load(PathBuf::from(String::from(config_file))) + .map_err(|e| format!("{}", e))?; let host = matches.value_of("address").unwrap(); // safe by clap let port = matches.value_of("port").map(u16::from_str) .transpose() - .unwrap_or_else(|e| { - eprintln!("Parsing port failed: {:?}", e); - std::process::exit(1) - }) + .map_err(|e| format!("Parsing port failed: {:?}", e))? .unwrap(); // safe by clap rocket::custom({ let mut c = rocket::config::Config::production(); - c.set_address(host).expect(&format!("Using host address failed: {}", host)); + c.set_address(host).map_err(|e| format!("Using host address failed: {}: {}", host, e))?; c.set_port(port); c }) .manage(config) .mount("/", routes![index, search, query]) .launch(); + Ok(()) } |