From 9c146367353d575798cba0df187101e899cc2067 Mon Sep 17 00:00:00 2001 From: VC Date: Mon, 14 Nov 2022 14:25:08 +0100 Subject: [PATCH 1/3] refactor: avoid Box::new syntax, prefer into() --- src/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/state.rs b/src/state.rs index d880aa3..99aaa05 100644 --- a/src/state.rs +++ b/src/state.rs @@ -87,7 +87,7 @@ pub fn migrate_db(d: &str, s: &str) -> Result<(), Box> { match res { Err(e) => match e.to_string().as_str() { "duplicate column name: twitter_screen_name" => Ok(()), - _ => Err(Box::new(e)), + _ => Err(e.into()), }, _ => Ok(()), } From 78924f6eeba2fba39d47cfea312876e1f8d40320 Mon Sep 17 00:00:00 2001 From: VC Date: Mon, 14 Nov 2022 14:26:25 +0100 Subject: [PATCH 2/3] refactor: simpler error bubbling inside async block --- src/util.rs | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/util.rs b/src/util.rs index e994e2e..4409d64 100644 --- a/src/util.rs +++ b/src/util.rs @@ -45,33 +45,16 @@ pub async fn generate_media_ids( let task = tokio::task::spawn(async move { info!("Start treating {}", media.media_url_https); // get the tweet embedded media - let local_tweet_media_path = match get_tweet_media(&media, &cache_path).await { - Ok(l) => l, - Err(e) => { - return Err(ScootalooError::new(&format!( - "Cannot get tweet media for {}: {}", - &media.url, e - ))) - } - }; + let local_tweet_media_path = get_tweet_media(&media, &cache_path).await?; // upload media to Mastodon - let mastodon_media = mastodon.media(Cow::from(local_tweet_media_path.to_owned())); + let mastodon_media = + mastodon.media(Cow::from(local_tweet_media_path.to_owned()))?; // at this point, we can safely erase the original file // it doesn’t matter if we can’t remove, cache_media fn is idempotent remove_file(&local_tweet_media_path).await.ok(); - let mastodon_media = match mastodon_media { - Ok(m) => m, - Err(e) => { - return Err(ScootalooError::new(&format!( - "Attachment {} cannot be uploaded to Mastodon Instance: {}", - &local_tweet_media_path, e - ))) - } - }; - - Ok((i, mastodon_media.id)) + Ok::<(usize, String), ScootalooError>((i, mastodon_media.id)) }); tasks.push(task); @@ -81,7 +64,7 @@ pub async fn generate_media_ids( match task.await { // insert the media at the right place Ok(Ok((i, v))) => media_ids[i] = v, - Ok(Err(e)) => warn!("{}", e), + Ok(Err(e)) => warn!("Cannot treat media: {}", e), Err(e) => error!("Something went wrong when joining the main thread: {}", e), } } From 822f4044c605fb4cadd8836a430563d5eccb2b9e Mon Sep 17 00:00:00 2001 From: VC Date: Mon, 14 Nov 2022 14:26:37 +0100 Subject: [PATCH 3/3] chore: bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e87f90..d7ce7ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2099,7 +2099,7 @@ dependencies = [ [[package]] name = "scootaloo" -version = "0.8.1" +version = "0.8.2" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 6341928..83d0d5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scootaloo" -version = "0.8.1" +version = "0.8.2" authors = ["VC "] edition = "2021"