Skip to content
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: 6 additions & 4 deletions src/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Mutex<Box<dyn Feed>>> =
Arc::new(Mutex::new(Box::new(self.clone()) as Box<dyn Feed>));
Expand Down Expand Up @@ -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
));
Expand Down Expand Up @@ -275,7 +276,8 @@ impl FeedItem {
self.published_at,
)
.execute(&self.db)
.await?;
.await
.with_context(|| format!("guid: '{}' link: '{}'", self.guid, self.link))?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};

Expand Down Expand Up @@ -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
}
Expand Down