From a6787d06889d18ad2a8f6210486e14d48877911f Mon Sep 17 00:00:00 2001 From: Troy Date: Thu, 16 Jan 2025 21:21:51 +0000 Subject: [PATCH] main return more specific type --- Cargo.lock | 9 ++++++++- Cargo.toml | 1 + src/data.rs | 13 +++++++++---- src/main.rs | 5 ++--- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c578bd..f2dbf27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,6 +81,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "anyhow" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" + [[package]] name = "atom_syndication" version = "0.12.6" @@ -1025,8 +1031,9 @@ dependencies = [ [[package]] name = "packard" -version = "0.0.1" +version = "0.0.2" dependencies = [ + "anyhow", "chrono", "clap", "futures", diff --git a/Cargo.toml b/Cargo.toml index e28e8c5..2fca284 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ toml = "0.8.19" xdg = "2.5.2" futures = "0.3.31" indicatif = "0.17.9" +anyhow = "1.0.95" [profile.dev] opt-level = 0 diff --git a/src/data.rs b/src/data.rs index aecaa0b..ccf5112 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,9 +1,9 @@ +use anyhow::{Context, Result}; use chrono::{DateTime, Utc}; use futures::future::join_all; use indicatif::ProgressBar; use reqwest::get; use rss::Channel; -use std::error::Error; #[derive(Debug)] pub struct FeedItem { @@ -13,9 +13,14 @@ pub struct FeedItem { pub pub_date: DateTime, } -async fn fetch_rss(url: &str, pb: &ProgressBar) -> Result> { - let response = get(url).await?.text().await?; - let channel = Channel::read_from(response.as_bytes())?; +async fn fetch_rss(url: &str, pb: &ProgressBar) -> Result { + let response = get(url) + .await + .context("Failed to send request")? + .text() + .await + .context("Failed to read response text")?; + let channel = Channel::read_from(response.as_bytes()).context("Failed to parse RSS feed")?; pb.inc(1); pb.set_message(format!("Processing: {}", channel.title)); Ok(channel) diff --git a/src/main.rs b/src/main.rs index 6226b99..9e33a83 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,12 @@ use indicatif::ProgressStyle; -use std::error::Error; -use tokio; +use tokio::io; mod config; mod data; mod utils; #[tokio::main] -async fn main() -> Result<(), Box> { +async fn main() -> Result<(), io::Error> { let config = config::validate_config(); let args = config::parse_cli(); let (count, skip_amount, list) = config::collate_values(args, &config);