Skip to content

Commit

Permalink
Remove intentional panics
Browse files Browse the repository at this point in the history
  • Loading branch information
dyegomb committed Jan 10, 2024
2 parents 78d1a50 + 5d36d99 commit 6975e30
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 18 deletions.
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
strip = "symbols"
# strip = true
panic = "abort"
debug = false
debug-assertions = false
overflow-checks = false
7 changes: 4 additions & 3 deletions gitlabapi/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion mailsender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down
4 changes: 2 additions & 2 deletions mailsender/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ This is a <b>test message</b>. :-)
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),
};
};
}
Expand Down
8 changes: 6 additions & 2 deletions mailsender/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ impl SmtpUtils for SmtpConfig {
destination: &Option<String>,
) -> Message {
if !self.is_valid() {
panic!("Smtp configuration is invalid")
error!("Smtp configuration is invalid");
std::process::exit(31)
};

let concat_subject = format!(
Expand Down Expand Up @@ -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)
}
}
}
}
12 changes: 9 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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)
}
},
};

Expand Down Expand Up @@ -101,7 +107,7 @@ async fn main() {
JobScope::Pending,
JobScope::Running,
JobScope::WaitingForResource,
// JobScope::Manual,
JobScope::Manual,
];

while let Some(result) = actions.next().await {
Expand Down
11 changes: 9 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();
Expand All @@ -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)
}
}
}

Expand Down

0 comments on commit 6975e30

Please sign in to comment.