Skip to content

Cleanup error handling #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# CHANGELOG

`@rfcbot` is Rust's automated process manager for RFCs, tracking issues, etc.
As such, this application does not follow semver of any form.

However, we do maintain this changelog explaining high level changes to the way
rfcbot behaves so that the people who develop rfcbot or interact with it can
understand the bot better.

## Changes
57 changes: 23 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ rocket = "0.3.3"
rocket_codegen = "0.3.3"
rocket_contrib = "0.3.3"
rust-crypto = "0.2.36"
serde = "1.0"
serde_derive = "1.0"
serde = "1.0.59"
serde_derive = "1.0.59"
serde_json = "1.0"
toml = "0.4"
url = "1.4"
Expand Down
23 changes: 6 additions & 17 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,17 @@ pub fn init() -> Result<Config, Vec<&'static str>> {
.collect::<BTreeMap<_, _>>();

let db_url = vars.remove(DB_URL).unwrap();
let db_pool_size = vars.remove(DB_POOL_SIZE).unwrap();
let db_pool_size = match db_pool_size.parse::<u32>() {
Ok(size) => size,
Err(_) => return Err(vec![DB_POOL_SIZE]),
};
let db_pool_size = vars.remove(DB_POOL_SIZE).unwrap().parse::<u32>();
let db_pool_size = ok_or!(db_pool_size, throw!(vec![DB_POOL_SIZE]));

let gh_token = vars.remove(GITHUB_TOKEN).unwrap();
let gh_ua = vars.remove(GITHUB_UA).unwrap();

let gh_interval = vars.remove(GITHUB_INTERVAL).unwrap();
let gh_interval = match gh_interval.parse::<u64>() {
Ok(interval) => interval,
Err(_) => return Err(vec![GITHUB_INTERVAL]),
};
let gh_interval = vars.remove(GITHUB_INTERVAL).unwrap().parse::<u64>();
let gh_interval = ok_or!(gh_interval, throw!(vec![GITHUB_INTERVAL]));

let post_comments = vars.remove(POST_COMMENTS).unwrap();
let post_comments = match post_comments.parse::<bool>() {
Ok(pc) => pc,
Err(_) => return Err(vec![POST_COMMENTS]),
};
let post_comments = vars.remove(POST_COMMENTS).unwrap().parse::<bool>();
let post_comments = ok_or!(post_comments, throw!(vec![POST_COMMENTS]));

let webhook_secrets = vars.remove(GITHUB_WEBHOOK_SECRETS).unwrap();
let webhook_secrets = webhook_secrets.split(',').map(String::from).collect();
Expand All @@ -106,11 +97,9 @@ pub fn init() -> Result<Config, Vec<&'static str>> {
})

} else {

Err(vars.iter()
.filter(|&(_, v)| v.is_err())
.map(|(&k, _)| k)
.collect())

}
}
Loading