Skip to content

Commit

Permalink
Merge pull request #65 from MostroP2P/better-error-handling
Browse files Browse the repository at this point in the history
Better error handling
  • Loading branch information
grunch authored Nov 6, 2024
2 parents 50aa20e + ac4cf2a commit 5f19abc
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/rating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,18 @@ impl Rating {

for tag in tags.into_iter() {
let t = tag.to_vec();
match t.first().unwrap().as_str() {
"total_reviews" => total_reviews = t.get(1).unwrap().parse::<u64>()?,
"total_rating" => total_rating = t.get(1).unwrap().parse::<f64>()?,
"last_rating" => last_rating = t.get(1).unwrap().parse::<u8>()?,
"max_rate" => max_rate = t.get(1).unwrap().parse::<u8>()?,
"min_rate" => min_rate = t.get(1).unwrap().parse::<u8>()?,
let key = t
.first()
.ok_or_else(|| anyhow::anyhow!("Missing tag key"))?;
let value = t
.get(1)
.ok_or_else(|| anyhow::anyhow!("Missing tag value"))?;
match key.as_str() {
"total_reviews" => total_reviews = value.parse::<u64>()?,
"total_rating" => total_rating = value.parse::<f64>()?,
"last_rating" => last_rating = value.parse::<u8>()?,
"max_rate" => max_rate = value.parse::<u8>()?,
"min_rate" => min_rate = value.parse::<u8>()?,
_ => {}
}
}
Expand Down

0 comments on commit 5f19abc

Please sign in to comment.