From 22cf00fd98fe94958b97ed5803fa8e7d0493d157 Mon Sep 17 00:00:00 2001 From: silverpill Date: Wed, 11 Jan 2023 18:37:39 +0000 Subject: [PATCH] Propagate database errors returned by importer in search_profiles_or_import() --- src/activitypub/mod.rs | 2 ++ src/mastodon_api/search/helpers.rs | 44 ++++++++++++++++++------------ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/activitypub/mod.rs b/src/activitypub/mod.rs index db6e13a..b9c0fe8 100644 --- a/src/activitypub/mod.rs +++ b/src/activitypub/mod.rs @@ -12,3 +12,5 @@ pub mod queues; mod receiver; pub mod views; mod vocabulary; + +pub use receiver::HandlerError; diff --git a/src/mastodon_api/search/helpers.rs b/src/mastodon_api/search/helpers.rs index 32ce0eb..884e1aa 100644 --- a/src/mastodon_api/search/helpers.rs +++ b/src/mastodon_api/search/helpers.rs @@ -11,6 +11,7 @@ use crate::activitypub::{ import_profile_by_actor_address, }, identifiers::{parse_local_actor_id, parse_local_object_id}, + HandlerError, }; use crate::config::Config; use crate::database::DatabaseError; @@ -117,25 +118,32 @@ async fn search_profiles_or_import( maybe_hostname.as_ref(), limit, ).await?; - if profiles.is_empty() && maybe_hostname.is_some() { - let actor_address = ActorAddress { - username: username, - hostname: maybe_hostname.unwrap(), + if profiles.is_empty() { + if let Some(hostname) = maybe_hostname { + let actor_address = ActorAddress { username, hostname }; + match import_profile_by_actor_address( + db_client, + &config.instance(), + &config.media_dir(), + &actor_address, + ).await { + Ok(profile) => { + profiles.push(profile); + }, + Err(HandlerError::DatabaseError(db_error)) => { + // Propagate database errors + return Err(db_error); + }, + Err(other_error) => { + log::warn!( + "failed to import profile {}: {}", + actor_address, + other_error, + ); + }, + }; }; - match import_profile_by_actor_address( - db_client, - &config.instance(), - &config.media_dir(), - &actor_address, - ).await { - Ok(profile) => { - profiles.push(profile); - }, - Err(err) => { - log::warn!("{}", err); - }, - } - } + }; Ok(profiles) }