diff --git a/Cargo.toml b/Cargo.toml index ff0d393..8dbde44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" [dependencies] # tokio = { version = "1", features = ["full"] } -tokio = { version = "1", features = ["time", "macros", "rt", "rt-multi-thread"] } +tokio = { version = "1", default-features = false, features = ["time", "macros", "rt", "rt-multi-thread"] } futures = "0.3" log = { version = "0.4", features = ["max_level_debug", "release_max_level_info"] } env_logger = "0.10" @@ -39,8 +39,12 @@ opt-level = 0 [profile.release] codegen-units = 1 -opt-level = 3 +# opt-level = 3 +opt-level = "z" lto = "fat" -# strip = "symbols" -strip = true -panic = "abort" \ No newline at end of file +strip = "symbols" +# strip = true +panic = "abort" +debug = false +debug-assertions = false +overflow-checks = false \ No newline at end of file diff --git a/gitlabapi/src/utils.rs b/gitlabapi/src/utils.rs index 17d6388..e6188bb 100644 --- a/gitlabapi/src/utils.rs +++ b/gitlabapi/src/utils.rs @@ -32,7 +32,8 @@ impl GitlabJOB { }, Err(error) => { - panic!("Couldn't construct the api caller: {}", error) + error!("Couldn't construct the api caller: {}", error); + std::process::exit(11) } } } @@ -53,8 +54,8 @@ impl GitlabJOB { match reqwest::Url::parse(&new_uri) { Ok(url) => url, Err(error) => { - // error!("Error while parsing url: {}", new_uri); - panic!("Error while parsing url \"{}\": {}", new_uri, error) + error!("Error while parsing url \"{}\": {}", new_uri, error); + std::process::exit(12) } } } diff --git a/mailsender/Cargo.toml b/mailsender/Cargo.toml index 8b13471..6a53e49 100644 --- a/mailsender/Cargo.toml +++ b/mailsender/Cargo.toml @@ -11,7 +11,7 @@ merge = "0.1" serde = { version = "1.0", features = ["derive"] } log = { version = "0.4", features = ["max_level_debug", "release_max_level_info"] } # tokio = { version = "1", features = ["full"] } -tokio = { version = "1", features = ["time", "macros"] } +tokio = { version = "1", default-features = false, features = ["time", "macros"] } configloader = { path = "../configloader"} diff --git a/mailsender/src/tests.rs b/mailsender/src/tests.rs index 0018f2a..942a456 100644 --- a/mailsender/src/tests.rs +++ b/mailsender/src/tests.rs @@ -121,11 +121,11 @@ This is a test message. :-) if let Some(relay) = mailsender.relay { match relay.send(&mail_message) { Ok(_) => debug!("Message 1 sent"), - Err(err) => panic!("{}", err), + Err(err) => error!("{}", err), }; match relay.send(&mail_message2) { Ok(_) => debug!("Message 2 sent"), - Err(err) => panic!("{}", err), + Err(err) => error!("{}", err), }; }; } diff --git a/mailsender/src/utils.rs b/mailsender/src/utils.rs index 66ebeb1..b78692e 100644 --- a/mailsender/src/utils.rs +++ b/mailsender/src/utils.rs @@ -41,7 +41,8 @@ impl SmtpUtils for SmtpConfig { destination: &Option, ) -> Message { if !self.is_valid() { - panic!("Smtp configuration is invalid") + error!("Smtp configuration is invalid"); + std::process::exit(31) }; let concat_subject = format!( @@ -81,7 +82,10 @@ impl SmtpUtils for SmtpConfig { .body(message) { Ok(message) => message, - Err(_) => panic!("Couldn't build a mail message"), + Err(_) => { + error!("Couldn't build a mail message"); + std::process::exit(32) + } } } } diff --git a/src/main.rs b/src/main.rs index a6eb319..8b9bec8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,7 +61,10 @@ async fn main() { let config = match Config::load_config() { Ok(conf) => conf, - Err(err) => panic!("Error loading configurations. {}", err), + Err(err) => { + error!("Error loading configurations. {}", err); + std::process::exit(1) + } }; let mail_relay_handle = tokio::spawn(utils::mailrelay_buid(config.clone())); @@ -73,7 +76,10 @@ async fn main() { Some(group_id) => api.get_jobs(GroupID(group_id), JobScope::Manual).await, None => match config.project_id { Some(proj_id) => api.get_jobs(ProjectID(proj_id), JobScope::Manual).await, - None => panic!("There's no project to scan for jobs."), + None => { + error!("There's no project to scan for jobs."); + std::process::exit(2) + } }, }; @@ -101,7 +107,7 @@ async fn main() { JobScope::Pending, JobScope::Running, JobScope::WaitingForResource, - // JobScope::Manual, + JobScope::Manual, ]; while let Some(result) = actions.next().await { diff --git a/src/tests.rs b/src/tests.rs index 26bcc1a..0858887 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -3,6 +3,7 @@ mod integration_tests { use crate::*; // use std::io::Write; use log::debug; + use std::process::exit; fn init() { let _ = env_logger::builder() @@ -22,7 +23,10 @@ mod integration_tests { let token_trigger = match env::var("TESTE_TOKENTRIG") { Ok(value) => value, - Err(_) => panic!("No token to trigger a new job"), + Err(_) => { + error!("No token to trigger a new job"); + exit(1) + } }; init(); @@ -47,7 +51,10 @@ mod integration_tests { match api.post_json(url, json_post).await { Ok(resp) => debug!("New pipeline created:\n{:?}", resp), - Err(error) => panic!("Failed to create new pipeline: {}", error), + Err(error) => { + error!("Failed to create new pipeline: {}", error); + exit(1) + } } }