commit 6397d1ece16453ad239561e06deebb0a352cd85a from: witcher date: Fri Feb 24 20:59:47 2023 UTC style(anyhow): Make `context` calls lazy commit - 4443c9574543ad11d1e2ea067f7b0a8ba20e7313 commit + 6397d1ece16453ad239561e06deebb0a352cd85a blob - a6f459c7137da0857306f3acf85a9b27620f1810 blob + 136c1bfa9246f2b06b5a9244755309d61db0db17 --- Cargo.lock +++ Cargo.lock @@ -1137,7 +1137,7 @@ dependencies = [ [[package]] name = "rss-email" -version = "0.4.1" +version = "0.4.2" dependencies = [ "anyhow", "atom_syndication", blob - 19c0347dd1a3404536a46f3453be28a332f5cc67 blob + 284b9035bb825496a7056c5689c715ad1b88ac96 --- src/config.rs +++ src/config.rs @@ -27,7 +27,7 @@ impl Config { pub fn new(config_path: impl AsRef) -> anyhow::Result { let mut string = String::new(); File::open(config_path.as_ref()) - .context(format!("File {:?} does not exist", &config_path.as_ref()))? + .with_context(|| format!("File {:?} does not exist", &config_path.as_ref()))? .read_to_string(&mut string)?; let config: Self = toml::de::from_str(&string)?; blob - 9756a552b44ec012afbaf5965457adc1acde6a5b blob + cdc2c1750a457cdc08f93f652ead8270c1ac3500 --- src/feed.rs +++ src/feed.rs @@ -17,7 +17,9 @@ where let url = url.as_ref(); let content = reqwest::get(url).await?.bytes().await?; match fetch_new_rss(&content[..]) { - Err(_) => fetch_new_atom(&content[..]).context(format!("Failed fetching feed for {url}")), + Err(_) => { + fetch_new_atom(&content[..]).with_context(|| format!("Failed fetching feed for {url}")) + } p => p, } } blob - 65ac5fd04dccdb411f0775c7185f365bd0c0d071 blob + 05e73279c485fb1800f2dd273817995e1ea9e2a3 --- src/main.rs +++ src/main.rs @@ -46,7 +46,7 @@ async fn main() -> anyhow::Result<()> { let config = Arc::new(AppConfig::new()?); let urls: Vec = BufReader::new( File::open(config.urls_path.as_str()) - .context(format!("File {:?} does not exist", &config.urls_path))?, + .with_context(|| format!("File {:?} does not exist", &config.urls_path))?, ) .lines() .filter_map(Result::ok) @@ -128,10 +128,12 @@ async fn fetch_feeds(urls: Vec, pool: &sqlx::P for i in posts { let conn = pool.acquire().await?; - db::insert_item(conn, &i).await.context(format!( - "Unable to insert item from {:?} with GUID {:?}", - i.url, i.guid - ))?; + db::insert_item(conn, &i).await.with_context(|| { + format!( + "Unable to insert item from {:?} with GUID {:?}", + i.url, i.guid + ) + })?; } }