diff --git a/src/feed.rs b/src/feed.rs index 46b4309..0c940fa 100644 --- a/src/feed.rs +++ b/src/feed.rs @@ -2,7 +2,7 @@ use core::fmt::Debug; use std::fmt; use std::sync::Arc; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, Context, Result}; use async_trait::async_trait; use sqlx::{Pool, Sqlite}; use tokio::sync::Mutex; @@ -135,7 +135,8 @@ impl Feed for RSSFeed { .timeout(std::time::Duration::from_secs(15)) .build()?; let response = client.get(&self.url).send().await?.text().await?; - let rssfeed = rss::Channel::read_from(response.as_bytes())?; + let rssfeed = rss::Channel::read_from(response.as_bytes()) + .with_context(|| format!("failed to parse RSS feed from '{}'", self.url))?; let feed: Arc>> = Arc::new(Mutex::new(Box::new(self.clone()) as Box)); @@ -211,7 +212,7 @@ impl Feed for AtomFeed { Ok(feed) => feed, Err(e) => { return Err(anyhow!( - "failed to parse atom feed from '{}': {}", + "failed to parse Atom feed from '{}': {}", self.url, e )); @@ -275,7 +276,8 @@ impl FeedItem { self.published_at, ) .execute(&self.db) - .await?; + .await + .with_context(|| format!("guid: '{}' link: '{}'", self.guid, self.link))?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index c474c1f..e739bcd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -140,7 +140,7 @@ async fn main() -> Result<()> { match item.save().await { Ok(_) => (), Err(e) => { - return Err(anyhow!("failed to save item '{}': {}", item.guid, e)); + return Err(anyhow!("failed to save item: {:?}", e)); } }; @@ -228,7 +228,7 @@ async fn main() -> Result<()> { match res { Ok(Ok(_)) => (), Ok(Err(e)) => { - println!("failed to save item: {}", e); + println!("{}", e); // This could happen if the feed item has a duplicate guid; // we don't want to exit in this case and ignore this for now }