Skip to content

Commit

Permalink
fix clippy, bump thiserror
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdallas committed Nov 6, 2022
1 parent 54942a1 commit 9abd30a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
12 changes: 6 additions & 6 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 @@ -19,7 +19,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value"] }
dotenv = "0.15.0"
md5 = "0.7.0"
thiserror = "1.0.22"
log = "0.4.11"
env_logger = "0.8.2"
futures = "0.3.8"
Expand All @@ -28,4 +27,5 @@ url = "2.2.0"
tempfile = "3.2.0"
which = "4.2.2"
mime = "0.3.16"
regex = "1.6.0"
regex = "1.6.0"
thiserror = "1.0"
2 changes: 2 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ pub enum GertError {
ToStringConversionError(#[from] ToStrError),
#[error("Could not convert from string")]
FromStringConversionError(#[from] FromStrError),
#[error("Error parsing JSON from {0}")]
JsonParseError(String)
}
16 changes: 10 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod subreddit;
mod user;
mod utils;

fn exit(msg: &str) {
fn exit(msg: &str) -> ! {
let err = clap::Error::with_description(msg, clap::ErrorKind::InvalidValue);
err.exit();
}
Expand Down Expand Up @@ -148,7 +148,7 @@ async fn main() -> Result<(), GertError> {
Some(url) => {
let parsed = url.parse::<url::Url>();
if parsed.is_err() {
return Ok(exit("Invalid URL"));
exit("Invalid URL");
}
Some(parsed.unwrap())
}
Expand All @@ -157,14 +157,14 @@ async fn main() -> Result<(), GertError> {

let limit = match matches.value_of("limit").unwrap().parse::<u32>() {
Ok(limit) => limit,
Err(_) => return Ok(exit("Limit must be a number")),
Err(_) => exit("Limit must be a number"),
};
let period = matches.value_of("period");
let feed = matches.value_of("feed").unwrap();
let pattern = match matches.value_of("match") {
Some(pattern) => match regex::Regex::new(pattern) {
Ok(reg) => reg,
Err(_) => return Ok(exit("Invalid regex pattern")),
Err(_) => exit("Invalid regex pattern"),
},
None => regex::Regex::new(".*").unwrap(),
};
Expand Down Expand Up @@ -266,10 +266,14 @@ async fn main() -> Result<(), GertError> {
let mut posts: Vec<Post> = Vec::with_capacity(limit as usize * subreddits.len());
if let Some(url) = single_url {
let url = format!("{}.json", url);
let single_listing: SingleListing = session.get(url).send().await?.json().await?;
let single_listing: SingleListing = match session.get(&url).send().await {
Ok(response) => response.json().await.map_err(|_| GertError::JsonParseError(url))?,
Err(_) => exit(&format!("Error fetching data from {}", &url))
};

let post = single_listing.0.data.children.into_iter().next().unwrap();
if post.data.url.is_none() {
return Ok(exit("Post contains no media"));
exit("Post contains no media")
}
posts.push(post);
} else {
Expand Down

0 comments on commit 9abd30a

Please sign in to comment.