From 5dea21d5313b011fb92126f60606a61343d34da0 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 10 Apr 2024 10:14:11 -0400 Subject: [PATCH] Convert all Result<..., LemmyError> into LemmyResult<...> Fixes #4613 (#4614) * Convert all Result<..., LemmyError> into LemmyResult<...> Fixes #4613 * Fixing clippy. --- crates/api/src/comment/distinguish.rs | 4 +- crates/api/src/comment/like.rs | 4 +- crates/api/src/comment/list_comment_likes.rs | 4 +- crates/api/src/comment/save.rs | 4 +- crates/api/src/comment_report/create.rs | 4 +- crates/api/src/comment_report/list.rs | 4 +- crates/api/src/comment_report/resolve.rs | 4 +- crates/api/src/community/add_mod.rs | 4 +- crates/api/src/community/ban.rs | 4 +- crates/api/src/community/block.rs | 4 +- crates/api/src/community/follow.rs | 4 +- crates/api/src/community/hide.rs | 4 +- crates/api/src/community/transfer.rs | 4 +- crates/api/src/lib.rs | 12 +-- crates/api/src/local_user/add_admin.rs | 4 +- crates/api/src/local_user/ban_person.rs | 4 +- crates/api/src/local_user/block.rs | 4 +- crates/api/src/local_user/change_password.rs | 4 +- .../local_user/change_password_after_reset.rs | 4 +- .../src/local_user/generate_totp_secret.rs | 4 +- crates/api/src/local_user/get_captcha.rs | 4 +- crates/api/src/local_user/list_banned.rs | 4 +- crates/api/src/local_user/list_logins.rs | 4 +- crates/api/src/local_user/list_media.rs | 4 +- crates/api/src/local_user/login.rs | 6 +- .../local_user/notifications/list_mentions.rs | 4 +- .../local_user/notifications/list_replies.rs | 4 +- .../local_user/notifications/mark_all_read.rs | 4 +- .../notifications/mark_mention_read.rs | 4 +- .../notifications/mark_reply_read.rs | 4 +- .../local_user/notifications/unread_count.rs | 4 +- crates/api/src/local_user/report_count.rs | 4 +- crates/api/src/local_user/save_settings.rs | 4 +- crates/api/src/local_user/update_totp.rs | 4 +- crates/api/src/local_user/validate_auth.rs | 4 +- crates/api/src/post/feature.rs | 4 +- crates/api/src/post/get_link_metadata.rs | 4 +- crates/api/src/post/hide.rs | 4 +- crates/api/src/post/like.rs | 4 +- crates/api/src/post/list_post_likes.rs | 4 +- crates/api/src/post/lock.rs | 4 +- crates/api/src/post/mark_read.rs | 4 +- crates/api/src/post/save.rs | 4 +- crates/api/src/post_report/create.rs | 4 +- crates/api/src/post_report/list.rs | 4 +- crates/api/src/post_report/resolve.rs | 4 +- crates/api/src/private_message/mark_read.rs | 4 +- .../api/src/private_message_report/create.rs | 4 +- crates/api/src/private_message_report/list.rs | 4 +- .../api/src/private_message_report/resolve.rs | 4 +- crates/api/src/site/block.rs | 4 +- crates/api/src/site/federated_instances.rs | 4 +- crates/api/src/site/leave_admin.rs | 4 +- crates/api/src/site/list_all_media.rs | 4 +- crates/api/src/site/mod_log.rs | 4 +- crates/api/src/site/purge/comment.rs | 4 +- crates/api/src/site/purge/community.rs | 4 +- crates/api/src/site/purge/person.rs | 4 +- crates/api/src/site/purge/post.rs | 4 +- .../site/registration_applications/approve.rs | 4 +- .../site/registration_applications/list.rs | 4 +- .../registration_applications/unread_count.rs | 4 +- crates/api_common/src/build_response.rs | 10 +-- crates/api_common/src/request.rs | 22 ++---- crates/api_common/src/utils.rs | 76 +++++++++---------- crates/api_crud/src/comment/create.rs | 6 +- crates/api_crud/src/comment/delete.rs | 4 +- crates/api_crud/src/comment/read.rs | 4 +- crates/api_crud/src/comment/remove.rs | 4 +- crates/api_crud/src/comment/update.rs | 4 +- crates/api_crud/src/community/create.rs | 4 +- crates/api_crud/src/community/delete.rs | 4 +- crates/api_crud/src/community/list.rs | 4 +- crates/api_crud/src/community/remove.rs | 4 +- crates/api_crud/src/community/update.rs | 4 +- crates/api_crud/src/custom_emoji/create.rs | 4 +- crates/api_crud/src/custom_emoji/delete.rs | 4 +- crates/api_crud/src/custom_emoji/update.rs | 4 +- crates/api_crud/src/post/create.rs | 4 +- crates/api_crud/src/post/delete.rs | 4 +- crates/api_crud/src/post/read.rs | 4 +- crates/api_crud/src/post/remove.rs | 4 +- crates/api_crud/src/post/update.rs | 4 +- crates/api_crud/src/private_message/create.rs | 4 +- crates/api_crud/src/private_message/delete.rs | 4 +- crates/api_crud/src/private_message/read.rs | 4 +- crates/api_crud/src/private_message/update.rs | 4 +- crates/api_crud/src/site/create.rs | 4 +- crates/api_crud/src/site/read.rs | 4 +- crates/api_crud/src/site/update.rs | 4 +- crates/api_crud/src/user/create.rs | 4 +- .../apub/src/activities/block/block_user.rs | 10 +-- crates/apub/src/activities/block/mod.rs | 20 ++--- .../src/activities/block/undo_block_user.rs | 8 +- .../apub/src/activities/community/announce.rs | 8 +- .../activities/community/collection_add.rs | 14 ++-- .../activities/community/collection_remove.rs | 10 +-- .../src/activities/community/lock_page.rs | 4 +- crates/apub/src/activities/community/mod.rs | 4 +- .../apub/src/activities/community/report.rs | 8 +- .../apub/src/activities/community/update.rs | 8 +- .../activities/create_or_update/comment.rs | 11 ++- .../src/activities/create_or_update/post.rs | 10 +-- .../create_or_update/private_message.rs | 8 +- crates/apub/src/activities/deletion/delete.rs | 10 +-- crates/apub/src/activities/deletion/mod.rs | 16 ++-- .../src/activities/deletion/undo_delete.rs | 8 +- .../apub/src/activities/following/accept.rs | 8 +- .../apub/src/activities/following/follow.rs | 10 +-- crates/apub/src/activities/following/mod.rs | 4 +- .../src/activities/following/undo_follow.rs | 8 +- crates/apub/src/activities/mod.rs | 17 ++--- crates/apub/src/activities/voting/mod.rs | 12 +-- .../apub/src/activities/voting/undo_vote.rs | 8 +- crates/apub/src/activities/voting/vote.rs | 8 +- crates/apub/src/activity_lists.rs | 4 +- crates/apub/src/api/list_comments.rs | 4 +- crates/apub/src/api/list_posts.rs | 4 +- crates/apub/src/api/read_community.rs | 4 +- crates/apub/src/api/read_person.rs | 4 +- crates/apub/src/api/resolve_object.rs | 6 +- crates/apub/src/api/search.rs | 4 +- crates/apub/src/api/user_settings_backup.rs | 6 +- .../src/collections/community_moderators.rs | 12 +-- .../apub/src/collections/community_outbox.rs | 11 +-- crates/apub/src/fetcher/mod.rs | 4 +- crates/apub/src/fetcher/post_or_comment.rs | 17 ++--- crates/apub/src/fetcher/search.rs | 16 ++-- .../src/fetcher/site_or_community_or_user.rs | 12 +-- crates/apub/src/fetcher/user_or_community.rs | 15 ++-- crates/apub/src/http/comment.rs | 4 +- crates/apub/src/http/community.rs | 19 +++-- crates/apub/src/http/mod.rs | 4 +- crates/apub/src/http/person.rs | 8 +- crates/apub/src/http/post.rs | 4 +- crates/apub/src/http/site.rs | 10 +-- crates/apub/src/lib.rs | 9 +-- crates/apub/src/mentions.rs | 6 +- crates/apub/src/objects/comment.rs | 13 ++-- crates/apub/src/objects/community.rs | 25 +++--- crates/apub/src/objects/instance.rs | 18 ++--- crates/apub/src/objects/mod.rs | 4 +- crates/apub/src/objects/person.rs | 16 ++-- crates/apub/src/objects/post.rs | 13 ++-- crates/apub/src/objects/private_message.rs | 13 ++-- .../protocol/activities/block/block_user.rs | 4 +- .../activities/block/undo_block_user.rs | 4 +- .../activities/community/collection_add.rs | 4 +- .../activities/community/collection_remove.rs | 4 +- .../activities/community/lock_page.rs | 6 +- .../protocol/activities/community/report.rs | 4 +- .../protocol/activities/community/update.rs | 4 +- .../activities/create_or_update/note.rs | 4 +- .../activities/create_or_update/page.rs | 4 +- .../protocol/activities/deletion/delete.rs | 4 +- .../activities/deletion/undo_delete.rs | 4 +- .../protocol/activities/voting/undo_vote.rs | 4 +- .../src/protocol/activities/voting/vote.rs | 4 +- .../src/protocol/collections/empty_outbox.rs | 4 +- crates/apub/src/protocol/mod.rs | 16 ++-- crates/apub/src/protocol/objects/group.rs | 4 +- crates/apub/src/protocol/objects/mod.rs | 10 +-- crates/apub/src/protocol/objects/note.rs | 6 +- crates/apub/src/protocol/objects/page.rs | 15 ++-- crates/db_schema/src/impls/actor_language.rs | 4 +- crates/db_schema/src/impls/local_site.rs | 14 ++-- crates/db_schema/src/impls/private_message.rs | 4 +- crates/db_schema/src/utils.rs | 14 ++-- crates/routes/src/feeds.rs | 25 +++--- crates/routes/src/lib.rs | 7 +- crates/routes/src/nodeinfo.rs | 6 +- crates/routes/src/webfinger.rs | 4 +- crates/utils/src/email.rs | 4 +- crates/utils/src/error.rs | 10 +-- crates/utils/src/settings/mod.rs | 6 +- crates/utils/src/utils/slurs.rs | 9 +-- src/code_migrations.rs | 27 +++---- src/lib.rs | 11 ++- src/main.rs | 4 +- src/scheduled_tasks.rs | 4 +- src/telemetry.rs | 8 +- 181 files changed, 591 insertions(+), 672 deletions(-) diff --git a/crates/api/src/comment/distinguish.rs b/crates/api/src/comment/distinguish.rs index a346bf4ca..dc2be8ad8 100644 --- a/crates/api/src/comment/distinguish.rs +++ b/crates/api/src/comment/distinguish.rs @@ -9,14 +9,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::{CommentView, LocalUserView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn distinguish_comment( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let orig_comment = CommentView::read(&mut context.pool(), data.comment_id, None).await?; check_community_user_action( diff --git a/crates/api/src/comment/like.rs b/crates/api/src/comment/like.rs index e15d74422..bfa522739 100644 --- a/crates/api/src/comment/like.rs +++ b/crates/api/src/comment/like.rs @@ -17,7 +17,7 @@ use lemmy_db_schema::{ traits::Likeable, }; use lemmy_db_views::structs::{CommentView, LocalUserView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; use std::ops::Deref; #[tracing::instrument(skip(context))] @@ -25,7 +25,7 @@ pub async fn like_comment( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; let mut recipient_ids = Vec::::new(); diff --git a/crates/api/src/comment/list_comment_likes.rs b/crates/api/src/comment/list_comment_likes.rs index b442cce23..649ae249d 100644 --- a/crates/api/src/comment/list_comment_likes.rs +++ b/crates/api/src/comment/list_comment_likes.rs @@ -5,7 +5,7 @@ use lemmy_api_common::{ utils::is_mod_or_admin, }; use lemmy_db_views::structs::{CommentView, LocalUserView, VoteView}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; /// Lists likes for a comment #[tracing::instrument(skip(context))] @@ -13,7 +13,7 @@ pub async fn list_comment_likes( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let comment_view = CommentView::read( &mut context.pool(), data.comment_id, diff --git a/crates/api/src/comment/save.rs b/crates/api/src/comment/save.rs index 95c08e701..f197ecb4c 100644 --- a/crates/api/src/comment/save.rs +++ b/crates/api/src/comment/save.rs @@ -8,14 +8,14 @@ use lemmy_db_schema::{ traits::Saveable, }; use lemmy_db_views::structs::{CommentView, LocalUserView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn save_comment( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let comment_saved_form = CommentSavedForm { comment_id: data.comment_id, person_id: local_user_view.person.id, diff --git a/crates/api/src/comment_report/create.rs b/crates/api/src/comment_report/create.rs index f8075460f..de40571fe 100644 --- a/crates/api/src/comment_report/create.rs +++ b/crates/api/src/comment_report/create.rs @@ -19,7 +19,7 @@ use lemmy_db_schema::{ traits::Reportable, }; use lemmy_db_views::structs::{CommentReportView, CommentView, LocalUserView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; /// Creates a comment report and notifies the moderators of the community #[tracing::instrument(skip(context))] @@ -27,7 +27,7 @@ pub async fn create_comment_report( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; let reason = data.reason.trim().to_string(); diff --git a/crates/api/src/comment_report/list.rs b/crates/api/src/comment_report/list.rs index f1577a77f..d2f723819 100644 --- a/crates/api/src/comment_report/list.rs +++ b/crates/api/src/comment_report/list.rs @@ -5,7 +5,7 @@ use lemmy_api_common::{ utils::check_community_mod_of_any_or_admin_action, }; use lemmy_db_views::{comment_report_view::CommentReportQuery, structs::LocalUserView}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; /// Lists comment reports for a community if an id is supplied /// or returns all comment reports for communities a user moderates @@ -14,7 +14,7 @@ pub async fn list_comment_reports( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let community_id = data.community_id; let comment_id = data.comment_id; let unresolved_only = data.unresolved_only.unwrap_or_default(); diff --git a/crates/api/src/comment_report/resolve.rs b/crates/api/src/comment_report/resolve.rs index 70e7d89f6..a663fdf74 100644 --- a/crates/api/src/comment_report/resolve.rs +++ b/crates/api/src/comment_report/resolve.rs @@ -6,7 +6,7 @@ use lemmy_api_common::{ }; use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable}; use lemmy_db_views::structs::{CommentReportView, LocalUserView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; /// Resolves or unresolves a comment report and notifies the moderators of the community #[tracing::instrument(skip(context))] @@ -14,7 +14,7 @@ pub async fn resolve_comment_report( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let report_id = data.report_id; let person_id = local_user_view.person.id; let report = CommentReportView::read(&mut context.pool(), report_id, person_id).await?; diff --git a/crates/api/src/community/add_mod.rs b/crates/api/src/community/add_mod.rs index 69692e58c..92799fb6b 100644 --- a/crates/api/src/community/add_mod.rs +++ b/crates/api/src/community/add_mod.rs @@ -15,14 +15,14 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::CommunityModeratorView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn add_mod_to_community( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let community_id = data.community_id; // Verify that only mods or admins can add mod diff --git a/crates/api/src/community/ban.rs b/crates/api/src/community/ban.rs index 91cb8884f..0ad9952df 100644 --- a/crates/api/src/community/ban.rs +++ b/crates/api/src/community/ban.rs @@ -21,7 +21,7 @@ use lemmy_db_schema::{ use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::PersonView; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, utils::validation::is_valid_body_field, }; @@ -30,7 +30,7 @@ pub async fn ban_from_community( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let banned_person_id = data.person_id; let remove_data = data.remove_data.unwrap_or(false); let expires = check_expire_time(data.expires)?; diff --git a/crates/api/src/community/block.rs b/crates/api/src/community/block.rs index fd4a5a01b..d5d8a0287 100644 --- a/crates/api/src/community/block.rs +++ b/crates/api/src/community/block.rs @@ -14,14 +14,14 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::CommunityView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn block_community( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let community_id = data.community_id; let person_id = local_user_view.person.id; let community_block_form = CommunityBlockForm { diff --git a/crates/api/src/community/follow.rs b/crates/api/src/community/follow.rs index bb7b80f00..94109192b 100644 --- a/crates/api/src/community/follow.rs +++ b/crates/api/src/community/follow.rs @@ -15,14 +15,14 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::CommunityView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn follow_community( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let community = Community::read(&mut context.pool(), data.community_id).await?; let mut community_follower_form = CommunityFollowerForm { community_id: community.id, diff --git a/crates/api/src/community/hide.rs b/crates/api/src/community/hide.rs index 27919a42b..997d88de3 100644 --- a/crates/api/src/community/hide.rs +++ b/crates/api/src/community/hide.rs @@ -15,14 +15,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn hide_community( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Verify its a admin (only admin can hide or unhide it) is_admin(&local_user_view)?; diff --git a/crates/api/src/community/transfer.rs b/crates/api/src/community/transfer.rs index 340bb6b63..399eeadae 100644 --- a/crates/api/src/community/transfer.rs +++ b/crates/api/src/community/transfer.rs @@ -15,7 +15,7 @@ use lemmy_db_schema::{ use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView}; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, location_info, }; @@ -26,7 +26,7 @@ pub async fn transfer_community( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let community_id = data.community_id; let mut community_mods = CommunityModeratorView::for_community(&mut context.pool(), community_id).await?; diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index d65ae0a28..498dff3bd 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -26,7 +26,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorExt2, LemmyErrorType, LemmyResult}, + error::{LemmyErrorExt, LemmyErrorExt2, LemmyErrorType, LemmyResult}, utils::slurs::check_slurs, }; use std::io::Cursor; @@ -44,7 +44,7 @@ pub mod site; pub mod sitemap; /// Converts the captcha to a base64 encoded wav audio file -pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> Result { +pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> LemmyResult { let letters = captcha.as_wav(); // Decode each wav file, concatenate the samples @@ -78,7 +78,7 @@ pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> Result Result<(), LemmyError> { +pub(crate) fn check_report_reason(reason: &str, local_site: &LocalSite) -> LemmyResult<()> { let slur_regex = &local_site_to_slur_regex(local_site); check_slurs(reason, slur_regex)?; @@ -91,7 +91,7 @@ pub(crate) fn check_report_reason(reason: &str, local_site: &LocalSite) -> Resul } } -pub fn read_auth_token(req: &HttpRequest) -> Result, LemmyError> { +pub fn read_auth_token(req: &HttpRequest) -> LemmyResult> { // Try reading jwt from auth header if let Ok(header) = Authorization::::parse(req) { Ok(Some(header.as_ref().token().to_string())) @@ -135,7 +135,7 @@ pub(crate) fn generate_totp_2fa_secret() -> String { Secret::generate_secret().to_string() } -fn build_totp_2fa(hostname: &str, username: &str, secret: &str) -> Result { +fn build_totp_2fa(hostname: &str, username: &str, secret: &str) -> LemmyResult { let sec = Secret::Raw(secret.as_bytes().to_vec()); let sec_bytes = sec .to_bytes() @@ -248,7 +248,7 @@ pub(crate) async fn ban_nonlocal_user_from_local_communities( pub async fn local_user_view_from_jwt( jwt: &str, context: &LemmyContext, -) -> Result { +) -> LemmyResult { let local_user_id = Claims::validate(jwt, context) .await .with_lemmy_type(LemmyErrorType::NotLoggedIn)?; diff --git a/crates/api/src/local_user/add_admin.rs b/crates/api/src/local_user/add_admin.rs index 502335876..6ebdbd08f 100644 --- a/crates/api/src/local_user/add_admin.rs +++ b/crates/api/src/local_user/add_admin.rs @@ -13,14 +13,14 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::PersonView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn add_admin( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Make sure user is an admin is_admin(&local_user_view)?; diff --git a/crates/api/src/local_user/ban_person.rs b/crates/api/src/local_user/ban_person.rs index f039c9a0c..f0e6ffc26 100644 --- a/crates/api/src/local_user/ban_person.rs +++ b/crates/api/src/local_user/ban_person.rs @@ -18,7 +18,7 @@ use lemmy_db_schema::{ use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::PersonView; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, utils::validation::is_valid_body_field, }; @@ -27,7 +27,7 @@ pub async fn ban_from_site( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Make sure user is an admin is_admin(&local_user_view)?; diff --git a/crates/api/src/local_user/block.rs b/crates/api/src/local_user/block.rs index cb345616b..46a1e44aa 100644 --- a/crates/api/src/local_user/block.rs +++ b/crates/api/src/local_user/block.rs @@ -9,14 +9,14 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::PersonView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn block_person( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let target_id = data.person_id; let person_id = local_user_view.person.id; diff --git a/crates/api/src/local_user/change_password.rs b/crates/api/src/local_user/change_password.rs index ab5b32dd9..50ee10bb6 100644 --- a/crates/api/src/local_user/change_password.rs +++ b/crates/api/src/local_user/change_password.rs @@ -11,7 +11,7 @@ use lemmy_api_common::{ }; use lemmy_db_schema::source::{local_user::LocalUser, login_token::LoginToken}; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn change_password( @@ -19,7 +19,7 @@ pub async fn change_password( req: HttpRequest, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { password_length_check(&data.new_password)?; // Make sure passwords match diff --git a/crates/api/src/local_user/change_password_after_reset.rs b/crates/api/src/local_user/change_password_after_reset.rs index 50a267d6a..9d759d7e9 100644 --- a/crates/api/src/local_user/change_password_after_reset.rs +++ b/crates/api/src/local_user/change_password_after_reset.rs @@ -10,13 +10,13 @@ use lemmy_db_schema::source::{ login_token::LoginToken, password_reset_request::PasswordResetRequest, }; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn change_password_after_reset( data: Json, context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { // Fetch the user_id from the token let token = data.token.clone(); let local_user_id = PasswordResetRequest::read_from_token(&mut context.pool(), &token) diff --git a/crates/api/src/local_user/generate_totp_secret.rs b/crates/api/src/local_user/generate_totp_secret.rs index 342a90a78..285fa2ad5 100644 --- a/crates/api/src/local_user/generate_totp_secret.rs +++ b/crates/api/src/local_user/generate_totp_secret.rs @@ -8,7 +8,7 @@ use lemmy_api_common::{ }; use lemmy_db_schema::source::local_user::{LocalUser, LocalUserUpdateForm}; use lemmy_db_views::structs::{LocalUserView, SiteView}; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorType, LemmyResult}; /// Generate a new secret for two-factor-authentication. Afterwards you need to call [toggle_totp] /// to enable it. This can only be called if 2FA is currently disabled. @@ -16,7 +16,7 @@ use lemmy_utils::error::{LemmyError, LemmyErrorType}; pub async fn generate_totp_secret( local_user_view: LocalUserView, context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { let site_view = SiteView::read_local(&mut context.pool()).await?; if local_user_view.local_user.totp_2fa_enabled { diff --git a/crates/api/src/local_user/get_captcha.rs b/crates/api/src/local_user/get_captcha.rs index 3d93a793c..ac64fa07c 100644 --- a/crates/api/src/local_user/get_captcha.rs +++ b/crates/api/src/local_user/get_captcha.rs @@ -17,10 +17,10 @@ use lemmy_db_schema::source::{ captcha_answer::{CaptchaAnswer, CaptchaAnswerForm}, local_site::LocalSite, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] -pub async fn get_captcha(context: Data) -> Result { +pub async fn get_captcha(context: Data) -> LemmyResult { let local_site = LocalSite::read(&mut context.pool()).await?; let mut res = HttpResponseBuilder::new(StatusCode::OK); res.insert_header(CacheControl(vec![CacheDirective::NoStore])); diff --git a/crates/api/src/local_user/list_banned.rs b/crates/api/src/local_user/list_banned.rs index 5c76d89a8..ba2c0d403 100644 --- a/crates/api/src/local_user/list_banned.rs +++ b/crates/api/src/local_user/list_banned.rs @@ -2,12 +2,12 @@ use actix_web::web::{Data, Json}; use lemmy_api_common::{context::LemmyContext, person::BannedPersonsResponse, utils::is_admin}; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::PersonView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; pub async fn list_banned_users( context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Make sure user is an admin is_admin(&local_user_view)?; diff --git a/crates/api/src/local_user/list_logins.rs b/crates/api/src/local_user/list_logins.rs index f1ae76be5..013236dcd 100644 --- a/crates/api/src/local_user/list_logins.rs +++ b/crates/api/src/local_user/list_logins.rs @@ -2,12 +2,12 @@ use actix_web::web::{Data, Json}; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::source::login_token::LoginToken; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; pub async fn list_logins( context: Data, local_user_view: LocalUserView, -) -> Result>, LemmyError> { +) -> LemmyResult>> { let logins = LoginToken::list(&mut context.pool(), local_user_view.local_user.id).await?; Ok(Json(logins)) diff --git a/crates/api/src/local_user/list_media.rs b/crates/api/src/local_user/list_media.rs index 25df8a4c2..bf69c4a34 100644 --- a/crates/api/src/local_user/list_media.rs +++ b/crates/api/src/local_user/list_media.rs @@ -5,14 +5,14 @@ use lemmy_api_common::{ }; use lemmy_db_schema::source::images::LocalImage; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn list_media( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let page = data.page; let limit = data.limit; let images = LocalImage::get_all_paged_by_local_user_id( diff --git a/crates/api/src/local_user/login.rs b/crates/api/src/local_user/login.rs index 4eae762be..8e3301af9 100644 --- a/crates/api/src/local_user/login.rs +++ b/crates/api/src/local_user/login.rs @@ -16,14 +16,14 @@ use lemmy_db_schema::{ RegistrationMode, }; use lemmy_db_views::structs::{LocalUserView, SiteView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn login( data: Json, req: HttpRequest, context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { let site_view = SiteView::read_local(&mut context.pool()).await?; // Fetch that username / email @@ -70,7 +70,7 @@ async fn check_registration_application( local_user_view: &LocalUserView, local_site: &LocalSite, pool: &mut DbPool<'_>, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { if (local_site.registration_mode == RegistrationMode::RequireApplication || local_site.registration_mode == RegistrationMode::Closed) && !local_user_view.local_user.accepted_application diff --git a/crates/api/src/local_user/notifications/list_mentions.rs b/crates/api/src/local_user/notifications/list_mentions.rs index 9f9ee3ae8..bf3cd8e0d 100644 --- a/crates/api/src/local_user/notifications/list_mentions.rs +++ b/crates/api/src/local_user/notifications/list_mentions.rs @@ -5,14 +5,14 @@ use lemmy_api_common::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::person_mention_view::PersonMentionQuery; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn list_mentions( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let sort = data.sort; let page = data.page; let limit = data.limit; diff --git a/crates/api/src/local_user/notifications/list_replies.rs b/crates/api/src/local_user/notifications/list_replies.rs index 555989721..d88595d96 100644 --- a/crates/api/src/local_user/notifications/list_replies.rs +++ b/crates/api/src/local_user/notifications/list_replies.rs @@ -5,14 +5,14 @@ use lemmy_api_common::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::comment_reply_view::CommentReplyQuery; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn list_replies( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let sort = data.sort; let page = data.page; let limit = data.limit; diff --git a/crates/api/src/local_user/notifications/mark_all_read.rs b/crates/api/src/local_user/notifications/mark_all_read.rs index d3667460b..558d276f7 100644 --- a/crates/api/src/local_user/notifications/mark_all_read.rs +++ b/crates/api/src/local_user/notifications/mark_all_read.rs @@ -6,13 +6,13 @@ use lemmy_db_schema::source::{ private_message::PrivateMessage, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn mark_all_notifications_read( context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let person_id = local_user_view.person.id; // Mark all comment_replies as read diff --git a/crates/api/src/local_user/notifications/mark_mention_read.rs b/crates/api/src/local_user/notifications/mark_mention_read.rs index 4cce598ac..9a839b2b4 100644 --- a/crates/api/src/local_user/notifications/mark_mention_read.rs +++ b/crates/api/src/local_user/notifications/mark_mention_read.rs @@ -9,14 +9,14 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::PersonMentionView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn mark_person_mention_as_read( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let person_mention_id = data.person_mention_id; let read_person_mention = PersonMention::read(&mut context.pool(), person_mention_id).await?; diff --git a/crates/api/src/local_user/notifications/mark_reply_read.rs b/crates/api/src/local_user/notifications/mark_reply_read.rs index f7b259c94..5b263145f 100644 --- a/crates/api/src/local_user/notifications/mark_reply_read.rs +++ b/crates/api/src/local_user/notifications/mark_reply_read.rs @@ -9,14 +9,14 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::CommentReplyView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn mark_reply_as_read( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let comment_reply_id = data.comment_reply_id; let read_comment_reply = CommentReply::read(&mut context.pool(), comment_reply_id).await?; diff --git a/crates/api/src/local_user/notifications/unread_count.rs b/crates/api/src/local_user/notifications/unread_count.rs index c0b1f0f2e..9d06f7c62 100644 --- a/crates/api/src/local_user/notifications/unread_count.rs +++ b/crates/api/src/local_user/notifications/unread_count.rs @@ -2,13 +2,13 @@ use actix_web::web::{Data, Json}; use lemmy_api_common::{context::LemmyContext, person::GetUnreadCountResponse}; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn unread_count( context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let person_id = local_user_view.person.id; let replies = CommentReplyView::get_unread_replies(&mut context.pool(), person_id).await?; diff --git a/crates/api/src/local_user/report_count.rs b/crates/api/src/local_user/report_count.rs index 3352f64eb..32448dcaa 100644 --- a/crates/api/src/local_user/report_count.rs +++ b/crates/api/src/local_user/report_count.rs @@ -10,14 +10,14 @@ use lemmy_db_views::structs::{ PostReportView, PrivateMessageReportView, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn report_count( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let person_id = local_user_view.person.id; let admin = local_user_view.local_user.admin; let community_id = data.community_id; diff --git a/crates/api/src/local_user/save_settings.rs b/crates/api/src/local_user/save_settings.rs index 972760a00..3fa835f58 100644 --- a/crates/api/src/local_user/save_settings.rs +++ b/crates/api/src/local_user/save_settings.rs @@ -25,7 +25,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_utils::{ - error::{LemmyError, LemmyErrorType}, + error::{LemmyErrorType, LemmyResult}, utils::validation::{is_valid_bio_field, is_valid_display_name, is_valid_matrix_id}, }; @@ -34,7 +34,7 @@ pub async fn save_user_settings( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let site_view = SiteView::read_local(&mut context.pool()).await?; let slur_regex = local_site_to_slur_regex(&site_view.local_site); diff --git a/crates/api/src/local_user/update_totp.rs b/crates/api/src/local_user/update_totp.rs index c8ca9f64e..c28ac7228 100644 --- a/crates/api/src/local_user/update_totp.rs +++ b/crates/api/src/local_user/update_totp.rs @@ -6,7 +6,7 @@ use lemmy_api_common::{ }; use lemmy_db_schema::source::local_user::{LocalUser, LocalUserUpdateForm}; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; /// Enable or disable two-factor-authentication. The current setting is determined from /// [LocalUser.totp_2fa_enabled]. @@ -21,7 +21,7 @@ pub async fn update_totp( data: Json, local_user_view: LocalUserView, context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { check_totp_2fa_valid( &local_user_view, &Some(data.totp_token.clone()), diff --git a/crates/api/src/local_user/validate_auth.rs b/crates/api/src/local_user/validate_auth.rs index d95195dc9..36d31ff01 100644 --- a/crates/api/src/local_user/validate_auth.rs +++ b/crates/api/src/local_user/validate_auth.rs @@ -4,7 +4,7 @@ use actix_web::{ HttpRequest, }; use lemmy_api_common::{context::LemmyContext, SuccessResponse}; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorType, LemmyResult}; /// Returns an error message if the auth token is invalid for any reason. Necessary because other /// endpoints silently treat any call with invalid auth as unauthenticated. @@ -12,7 +12,7 @@ use lemmy_utils::error::{LemmyError, LemmyErrorType}; pub async fn validate_auth( req: HttpRequest, context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { let jwt = read_auth_token(&req)?; if let Some(jwt) = jwt { local_user_view_from_jwt(&jwt, &context).await?; diff --git a/crates/api/src/post/feature.rs b/crates/api/src/post/feature.rs index 8c4b4978f..566ca3a0b 100644 --- a/crates/api/src/post/feature.rs +++ b/crates/api/src/post/feature.rs @@ -16,14 +16,14 @@ use lemmy_db_schema::{ PostFeatureType, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn feature_post( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let post_id = data.post_id; let orig_post = Post::read(&mut context.pool(), post_id).await?; diff --git a/crates/api/src/post/get_link_metadata.rs b/crates/api/src/post/get_link_metadata.rs index a6a0c973b..8bc425125 100644 --- a/crates/api/src/post/get_link_metadata.rs +++ b/crates/api/src/post/get_link_metadata.rs @@ -4,13 +4,13 @@ use lemmy_api_common::{ post::{GetSiteMetadata, GetSiteMetadataResponse}, request::fetch_link_metadata, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn get_link_metadata( data: Query, context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { let metadata = fetch_link_metadata(&data.url, false, &context).await?; Ok(Json(GetSiteMetadataResponse { metadata })) diff --git a/crates/api/src/post/hide.rs b/crates/api/src/post/hide.rs index 1adfa110d..f7c21ef31 100644 --- a/crates/api/src/post/hide.rs +++ b/crates/api/src/post/hide.rs @@ -2,7 +2,7 @@ use actix_web::web::{Data, Json}; use lemmy_api_common::{context::LemmyContext, post::HidePost, SuccessResponse}; use lemmy_db_schema::source::post::PostHide; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType, MAX_API_PARAM_ELEMENTS}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult, MAX_API_PARAM_ELEMENTS}; use std::collections::HashSet; #[tracing::instrument(skip(context))] @@ -10,7 +10,7 @@ pub async fn hide_post( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let post_ids = HashSet::from_iter(data.post_ids.clone()); if post_ids.len() > MAX_API_PARAM_ELEMENTS { diff --git a/crates/api/src/post/like.rs b/crates/api/src/post/like.rs index d99d2a5e2..1cbdba8e2 100644 --- a/crates/api/src/post/like.rs +++ b/crates/api/src/post/like.rs @@ -21,7 +21,7 @@ use lemmy_db_schema::{ traits::{Crud, Likeable}, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; use std::ops::Deref; #[tracing::instrument(skip(context))] @@ -29,7 +29,7 @@ pub async fn like_post( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; // Don't do a downvote if site has downvotes disabled diff --git a/crates/api/src/post/list_post_likes.rs b/crates/api/src/post/list_post_likes.rs index 84690a41b..a9b302f2e 100644 --- a/crates/api/src/post/list_post_likes.rs +++ b/crates/api/src/post/list_post_likes.rs @@ -6,7 +6,7 @@ use lemmy_api_common::{ }; use lemmy_db_schema::{source::post::Post, traits::Crud}; use lemmy_db_views::structs::{LocalUserView, VoteView}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; /// Lists likes for a post #[tracing::instrument(skip(context))] @@ -14,7 +14,7 @@ pub async fn list_post_likes( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let post = Post::read(&mut context.pool(), data.post_id).await?; is_mod_or_admin( &mut context.pool(), diff --git a/crates/api/src/post/lock.rs b/crates/api/src/post/lock.rs index b581f37a2..b48c415af 100644 --- a/crates/api/src/post/lock.rs +++ b/crates/api/src/post/lock.rs @@ -15,14 +15,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn lock_post( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let post_id = data.post_id; let orig_post = Post::read(&mut context.pool(), post_id).await?; diff --git a/crates/api/src/post/mark_read.rs b/crates/api/src/post/mark_read.rs index bfc455f4f..3e534675a 100644 --- a/crates/api/src/post/mark_read.rs +++ b/crates/api/src/post/mark_read.rs @@ -2,7 +2,7 @@ use actix_web::web::{Data, Json}; use lemmy_api_common::{context::LemmyContext, post::MarkPostAsRead, SuccessResponse}; use lemmy_db_schema::source::post::PostRead; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType, MAX_API_PARAM_ELEMENTS}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult, MAX_API_PARAM_ELEMENTS}; use std::collections::HashSet; #[tracing::instrument(skip(context))] @@ -10,7 +10,7 @@ pub async fn mark_post_as_read( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let post_ids = HashSet::from_iter(data.post_ids.clone()); if post_ids.len() > MAX_API_PARAM_ELEMENTS { diff --git a/crates/api/src/post/save.rs b/crates/api/src/post/save.rs index 164840770..05c7b3589 100644 --- a/crates/api/src/post/save.rs +++ b/crates/api/src/post/save.rs @@ -9,14 +9,14 @@ use lemmy_db_schema::{ traits::Saveable, }; use lemmy_db_views::structs::{LocalUserView, PostView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn save_post( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let post_saved_form = PostSavedForm { post_id: data.post_id, person_id: local_user_view.person.id, diff --git a/crates/api/src/post_report/create.rs b/crates/api/src/post_report/create.rs index 1327d7bb9..590c9af40 100644 --- a/crates/api/src/post_report/create.rs +++ b/crates/api/src/post_report/create.rs @@ -19,7 +19,7 @@ use lemmy_db_schema::{ traits::Reportable, }; use lemmy_db_views::structs::{LocalUserView, PostReportView, PostView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; /// Creates a post report and notifies the moderators of the community #[tracing::instrument(skip(context))] @@ -27,7 +27,7 @@ pub async fn create_post_report( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; let reason = data.reason.trim().to_string(); diff --git a/crates/api/src/post_report/list.rs b/crates/api/src/post_report/list.rs index 1f1aa9653..7d1d50b0b 100644 --- a/crates/api/src/post_report/list.rs +++ b/crates/api/src/post_report/list.rs @@ -5,7 +5,7 @@ use lemmy_api_common::{ utils::check_community_mod_of_any_or_admin_action, }; use lemmy_db_views::{post_report_view::PostReportQuery, structs::LocalUserView}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; /// Lists post reports for a community if an id is supplied /// or returns all post reports for communities a user moderates @@ -14,7 +14,7 @@ pub async fn list_post_reports( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let community_id = data.community_id; let post_id = data.post_id; let unresolved_only = data.unresolved_only.unwrap_or_default(); diff --git a/crates/api/src/post_report/resolve.rs b/crates/api/src/post_report/resolve.rs index ab6688012..a3cb85c6c 100644 --- a/crates/api/src/post_report/resolve.rs +++ b/crates/api/src/post_report/resolve.rs @@ -6,7 +6,7 @@ use lemmy_api_common::{ }; use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable}; use lemmy_db_views::structs::{LocalUserView, PostReportView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; /// Resolves or unresolves a post report and notifies the moderators of the community #[tracing::instrument(skip(context))] @@ -14,7 +14,7 @@ pub async fn resolve_post_report( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let report_id = data.report_id; let person_id = local_user_view.person.id; let report = PostReportView::read(&mut context.pool(), report_id, person_id).await?; diff --git a/crates/api/src/private_message/mark_read.rs b/crates/api/src/private_message/mark_read.rs index 6b089c0ab..7c213464b 100644 --- a/crates/api/src/private_message/mark_read.rs +++ b/crates/api/src/private_message/mark_read.rs @@ -8,14 +8,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn mark_pm_as_read( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Checking permissions let private_message_id = data.private_message_id; let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?; diff --git a/crates/api/src/private_message_report/create.rs b/crates/api/src/private_message_report/create.rs index 7aca9661b..de8ca390f 100644 --- a/crates/api/src/private_message_report/create.rs +++ b/crates/api/src/private_message_report/create.rs @@ -14,14 +14,14 @@ use lemmy_db_schema::{ traits::{Crud, Reportable}, }; use lemmy_db_views::structs::{LocalUserView, PrivateMessageReportView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn create_pm_report( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; let reason = data.reason.trim().to_string(); diff --git a/crates/api/src/private_message_report/list.rs b/crates/api/src/private_message_report/list.rs index 2dc3e6efc..79ef53e1c 100644 --- a/crates/api/src/private_message_report/list.rs +++ b/crates/api/src/private_message_report/list.rs @@ -8,14 +8,14 @@ use lemmy_db_views::{ private_message_report_view::PrivateMessageReportQuery, structs::LocalUserView, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn list_pm_reports( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { is_admin(&local_user_view)?; let unresolved_only = data.unresolved_only.unwrap_or_default(); diff --git a/crates/api/src/private_message_report/resolve.rs b/crates/api/src/private_message_report/resolve.rs index 202fdcd29..7d821a60c 100644 --- a/crates/api/src/private_message_report/resolve.rs +++ b/crates/api/src/private_message_report/resolve.rs @@ -6,14 +6,14 @@ use lemmy_api_common::{ }; use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable}; use lemmy_db_views::structs::{LocalUserView, PrivateMessageReportView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn resolve_pm_report( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { is_admin(&local_user_view)?; let report_id = data.report_id; diff --git a/crates/api/src/site/block.rs b/crates/api/src/site/block.rs index 7d28e43d5..823dda612 100644 --- a/crates/api/src/site/block.rs +++ b/crates/api/src/site/block.rs @@ -9,14 +9,14 @@ use lemmy_db_schema::{ traits::Blockable, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn block_instance( data: Json, local_user_view: LocalUserView, context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { let instance_id = data.instance_id; let person_id = local_user_view.person.id; if local_user_view.person.instance_id == instance_id { diff --git a/crates/api/src/site/federated_instances.rs b/crates/api/src/site/federated_instances.rs index 8f224b2eb..5943cfd9a 100644 --- a/crates/api/src/site/federated_instances.rs +++ b/crates/api/src/site/federated_instances.rs @@ -5,12 +5,12 @@ use lemmy_api_common::{ utils::build_federated_instances, }; use lemmy_db_views::structs::SiteView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn get_federated_instances( context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { let site_view = SiteView::read_local(&mut context.pool()).await?; let federated_instances = build_federated_instances(&site_view.local_site, &mut context.pool()).await?; diff --git a/crates/api/src/site/leave_admin.rs b/crates/api/src/site/leave_admin.rs index f2db0fc26..52b8a32ef 100644 --- a/crates/api/src/site/leave_admin.rs +++ b/crates/api/src/site/leave_admin.rs @@ -14,7 +14,7 @@ use lemmy_db_schema::{ use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView}; use lemmy_db_views_actor::structs::PersonView; use lemmy_utils::{ - error::{LemmyError, LemmyErrorType}, + error::{LemmyErrorType, LemmyResult}, VERSION, }; @@ -22,7 +22,7 @@ use lemmy_utils::{ pub async fn leave_admin( context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { is_admin(&local_user_view)?; // Make sure there isn't just one admin (so if one leaves, there will still be one left) diff --git a/crates/api/src/site/list_all_media.rs b/crates/api/src/site/list_all_media.rs index 495e72e48..49132cd64 100644 --- a/crates/api/src/site/list_all_media.rs +++ b/crates/api/src/site/list_all_media.rs @@ -6,14 +6,14 @@ use lemmy_api_common::{ }; use lemmy_db_schema::source::images::LocalImage; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn list_all_media( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Only let admins view all media is_admin(&local_user_view)?; diff --git a/crates/api/src/site/mod_log.rs b/crates/api/src/site/mod_log.rs index 1a4148d89..8f5538566 100644 --- a/crates/api/src/site/mod_log.rs +++ b/crates/api/src/site/mod_log.rs @@ -24,7 +24,7 @@ use lemmy_db_views_moderator::structs::{ ModTransferCommunityView, ModlogListParams, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use ModlogActionType::*; #[tracing::instrument(skip(context))] @@ -32,7 +32,7 @@ pub async fn get_mod_log( data: Query, context: Data, local_user_view: Option, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; check_private_instance(&local_user_view, &local_site)?; diff --git a/crates/api/src/site/purge/comment.rs b/crates/api/src/site/purge/comment.rs index a06085f24..cbb3637f0 100644 --- a/crates/api/src/site/purge/comment.rs +++ b/crates/api/src/site/purge/comment.rs @@ -15,14 +15,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::{CommentView, LocalUserView}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn purge_comment( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Only let admin purge an item is_admin(&local_user_view)?; diff --git a/crates/api/src/site/purge/community.rs b/crates/api/src/site/purge/community.rs index 61e58ba04..96c9c19cd 100644 --- a/crates/api/src/site/purge/community.rs +++ b/crates/api/src/site/purge/community.rs @@ -16,14 +16,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn purge_community( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Only let admin purge an item is_admin(&local_user_view)?; diff --git a/crates/api/src/site/purge/person.rs b/crates/api/src/site/purge/person.rs index 6023d7b41..a8233f76d 100644 --- a/crates/api/src/site/purge/person.rs +++ b/crates/api/src/site/purge/person.rs @@ -16,14 +16,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn purge_person( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Only let admin purge an item is_admin(&local_user_view)?; diff --git a/crates/api/src/site/purge/post.rs b/crates/api/src/site/purge/post.rs index 28e6668ff..ff34c471a 100644 --- a/crates/api/src/site/purge/post.rs +++ b/crates/api/src/site/purge/post.rs @@ -16,14 +16,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn purge_post( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Only let admin purge an item is_admin(&local_user_view)?; diff --git a/crates/api/src/site/registration_applications/approve.rs b/crates/api/src/site/registration_applications/approve.rs index 036a60e00..df3c3b428 100644 --- a/crates/api/src/site/registration_applications/approve.rs +++ b/crates/api/src/site/registration_applications/approve.rs @@ -13,13 +13,13 @@ use lemmy_db_schema::{ utils::diesel_option_overwrite, }; use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; pub async fn approve_registration_application( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let app_id = data.id; // Only let admins do this diff --git a/crates/api/src/site/registration_applications/list.rs b/crates/api/src/site/registration_applications/list.rs index 30ce9aaf2..df86b11d5 100644 --- a/crates/api/src/site/registration_applications/list.rs +++ b/crates/api/src/site/registration_applications/list.rs @@ -9,14 +9,14 @@ use lemmy_db_views::{ registration_application_view::RegistrationApplicationQuery, structs::LocalUserView, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; /// Lists registration applications, filterable by undenied only. pub async fn list_registration_applications( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; // Make sure user is an admin diff --git a/crates/api/src/site/registration_applications/unread_count.rs b/crates/api/src/site/registration_applications/unread_count.rs index 255859198..a12ecb1d3 100644 --- a/crates/api/src/site/registration_applications/unread_count.rs +++ b/crates/api/src/site/registration_applications/unread_count.rs @@ -6,12 +6,12 @@ use lemmy_api_common::{ }; use lemmy_db_schema::source::local_site::LocalSite; use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; pub async fn get_unread_registration_application_count( context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; // Only let admins do this diff --git a/crates/api_common/src/build_response.rs b/crates/api_common/src/build_response.rs index 990b96544..cd55d399c 100644 --- a/crates/api_common/src/build_response.rs +++ b/crates/api_common/src/build_response.rs @@ -25,7 +25,7 @@ use lemmy_db_schema::{ use lemmy_db_views::structs::{CommentView, LocalUserView, PostView}; use lemmy_db_views_actor::structs::CommunityView; use lemmy_utils::{ - error::LemmyError, + error::LemmyResult, utils::{markdown::markdown_to_html, mention::MentionData}, }; @@ -34,7 +34,7 @@ pub async fn build_comment_response( comment_id: CommentId, local_user_view: Option, recipient_ids: Vec, -) -> Result { +) -> LemmyResult { let person_id = local_user_view.map(|l| l.person.id); let comment_view = CommentView::read(&mut context.pool(), comment_id, person_id).await?; Ok(CommentResponse { @@ -47,7 +47,7 @@ pub async fn build_community_response( context: &LemmyContext, local_user_view: LocalUserView, community_id: CommunityId, -) -> Result, LemmyError> { +) -> LemmyResult> { let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), &local_user_view.person, community_id) .await .is_ok(); @@ -72,7 +72,7 @@ pub async fn build_post_response( community_id: CommunityId, person: &Person, post_id: PostId, -) -> Result, LemmyError> { +) -> LemmyResult> { let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), person, community_id) .await .is_ok(); @@ -94,7 +94,7 @@ pub async fn send_local_notifs( person: &Person, do_send_email: bool, context: &LemmyContext, -) -> Result, LemmyError> { +) -> LemmyResult> { let mut recipient_ids = Vec::new(); let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname()); diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index 06410b70c..fdd29a254 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -16,7 +16,7 @@ use lemmy_db_schema::{ }, }; use lemmy_utils::{ - error::{LemmyError, LemmyErrorType}, + error::{LemmyError, LemmyErrorType, LemmyResult}, settings::structs::{PictrsImageMode, Settings}, spawn_try_task, REQWEST_TIMEOUT, @@ -46,7 +46,7 @@ pub async fn fetch_link_metadata( url: &Url, generate_thumbnail: bool, context: &LemmyContext, -) -> Result { +) -> LemmyResult { info!("Fetching site metadata for url: {}", url); let response = context.client().get(url.as_str()).send().await?; @@ -132,7 +132,7 @@ pub fn generate_post_link_metadata( } /// Extract site metadata from HTML Opengraph attributes. -fn extract_opengraph_data(html_bytes: &[u8], url: &Url) -> Result { +fn extract_opengraph_data(html_bytes: &[u8], url: &Url) -> LemmyResult { let html = String::from_utf8_lossy(html_bytes); // Make sure the first line is doctype html @@ -240,10 +240,7 @@ struct PictrsPurgeResponse { /// - It might fail due to image being not local /// - It might not be an image /// - Pictrs might not be set up -pub async fn purge_image_from_pictrs( - image_url: &Url, - context: &LemmyContext, -) -> Result<(), LemmyError> { +pub async fn purge_image_from_pictrs(image_url: &Url, context: &LemmyContext) -> LemmyResult<()> { is_image_content_type(context.client(), image_url).await?; let alias = image_url @@ -278,7 +275,7 @@ pub async fn delete_image_from_pictrs( alias: &str, delete_token: &str, context: &LemmyContext, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let pictrs_config = context.settings().pictrs_config()?; let url = format!( "{}image/delete/{}/{}", @@ -296,10 +293,7 @@ pub async fn delete_image_from_pictrs( /// Retrieves the image with local pict-rs and generates a thumbnail. Returns the thumbnail url. #[tracing::instrument(skip_all)] -async fn generate_pictrs_thumbnail( - image_url: &Url, - context: &LemmyContext, -) -> Result { +async fn generate_pictrs_thumbnail(image_url: &Url, context: &LemmyContext) -> LemmyResult { let pictrs_config = context.settings().pictrs_config()?; match pictrs_config.image_mode() { @@ -349,7 +343,7 @@ async fn generate_pictrs_thumbnail( // TODO: get rid of this by reading content type from db #[tracing::instrument(skip_all)] -async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Result<(), LemmyError> { +async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> LemmyResult<()> { let response = client.get(url.as_str()).send().await?; if response .headers() @@ -369,7 +363,7 @@ pub async fn replace_image( new_image: &Option, old_image: &Option, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { if new_image.is_some() { // Ignore errors because image may be stored externally. if let Some(avatar) = &old_image { diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index 58e3f382b..9810e2390 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -60,7 +60,7 @@ pub async fn is_mod_or_admin( pool: &mut DbPool<'_>, person: &Person, community_id: CommunityId, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { check_user_valid(person)?; let is_mod_or_admin = CommunityView::is_mod_or_admin(pool, person.id, community_id).await?; @@ -76,7 +76,7 @@ pub async fn is_mod_or_admin_opt( pool: &mut DbPool<'_>, local_user_view: Option<&LocalUserView>, community_id: Option, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { if let Some(local_user_view) = local_user_view { if let Some(community_id) = community_id { is_mod_or_admin(pool, &local_user_view.person, community_id).await @@ -108,7 +108,7 @@ pub async fn check_community_mod_of_any_or_admin_action( } } -pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> { +pub fn is_admin(local_user_view: &LocalUserView) -> LemmyResult<()> { check_user_valid(&local_user_view.person)?; if !local_user_view.local_user.admin { Err(LemmyErrorType::NotAnAdmin)? @@ -122,7 +122,7 @@ pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> { pub fn is_top_mod( local_user_view: &LocalUserView, community_mods: &[CommunityModeratorView], -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { check_user_valid(&local_user_view.person)?; if local_user_view.person.id != community_mods @@ -137,7 +137,7 @@ pub fn is_top_mod( } #[tracing::instrument(skip_all)] -pub async fn get_post(post_id: PostId, pool: &mut DbPool<'_>) -> Result { +pub async fn get_post(post_id: PostId, pool: &mut DbPool<'_>) -> LemmyResult { Post::read(pool, post_id) .await .with_lemmy_type(LemmyErrorType::CouldntFindPost) @@ -148,14 +148,14 @@ pub async fn mark_post_as_read( person_id: PersonId, post_id: PostId, pool: &mut DbPool<'_>, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { PostRead::mark_as_read(pool, HashSet::from([post_id]), person_id) .await .with_lemmy_type(LemmyErrorType::CouldntMarkPostAsRead)?; Ok(()) } -pub fn check_user_valid(person: &Person) -> Result<(), LemmyError> { +pub fn check_user_valid(person: &Person) -> LemmyResult<()> { // Check for a site ban if person.banned { Err(LemmyErrorType::SiteBan)? @@ -230,7 +230,7 @@ pub async fn check_community_mod_action( } /// Don't allow creating reports for removed / deleted posts -pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> { +pub fn check_post_deleted_or_removed(post: &Post) -> LemmyResult<()> { if post.deleted || post.removed { Err(LemmyErrorType::Deleted)? } else { @@ -238,7 +238,7 @@ pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> { } } -pub fn check_comment_deleted_or_removed(comment: &Comment) -> Result<(), LemmyError> { +pub fn check_comment_deleted_or_removed(comment: &Comment) -> LemmyResult<()> { if comment.deleted || comment.removed { Err(LemmyErrorType::Deleted)? } else { @@ -252,7 +252,7 @@ pub async fn check_person_block( my_id: PersonId, potential_blocker_id: PersonId, pool: &mut DbPool<'_>, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let is_blocked = PersonBlock::read(pool, potential_blocker_id, my_id).await?; if is_blocked { Err(LemmyErrorType::PersonIsBlocked)? @@ -267,7 +267,7 @@ async fn check_community_block( community_id: CommunityId, person_id: PersonId, pool: &mut DbPool<'_>, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let is_blocked = CommunityBlock::read(pool, person_id, community_id).await?; if is_blocked { Err(LemmyErrorType::CommunityIsBlocked)? @@ -282,7 +282,7 @@ async fn check_instance_block( instance_id: InstanceId, person_id: PersonId, pool: &mut DbPool<'_>, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let is_blocked = InstanceBlock::read(pool, person_id, instance_id).await?; if is_blocked { Err(LemmyErrorType::InstanceIsBlocked)? @@ -298,7 +298,7 @@ pub async fn check_person_instance_community_block( community_instance_id: InstanceId, community_id: CommunityId, pool: &mut DbPool<'_>, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { check_person_block(my_id, potential_blocker_id, pool).await?; check_instance_block(community_instance_id, potential_blocker_id, pool).await?; check_community_block(community_id, potential_blocker_id, pool).await?; @@ -306,7 +306,7 @@ pub async fn check_person_instance_community_block( } #[tracing::instrument(skip_all)] -pub fn check_downvotes_enabled(score: i16, local_site: &LocalSite) -> Result<(), LemmyError> { +pub fn check_downvotes_enabled(score: i16, local_site: &LocalSite) -> LemmyResult<()> { if score == -1 && !local_site.enable_downvotes { Err(LemmyErrorType::DownvotesAreDisabled)? } else { @@ -316,7 +316,7 @@ pub fn check_downvotes_enabled(score: i16, local_site: &LocalSite) -> Result<(), /// Dont allow bots to do certain actions, like voting #[tracing::instrument(skip_all)] -pub fn check_bot_account(person: &Person) -> Result<(), LemmyError> { +pub fn check_bot_account(person: &Person) -> LemmyResult<()> { if person.bot_account { Err(LemmyErrorType::InvalidBotAction)? } else { @@ -328,7 +328,7 @@ pub fn check_bot_account(person: &Person) -> Result<(), LemmyError> { pub fn check_private_instance( local_user_view: &Option, local_site: &LocalSite, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { if local_user_view.is_none() && local_site.private_instance { Err(LemmyErrorType::InstanceIsPrivate)? } else { @@ -340,7 +340,7 @@ pub fn check_private_instance( pub async fn build_federated_instances( local_site: &LocalSite, pool: &mut DbPool<'_>, -) -> Result, LemmyError> { +) -> LemmyResult> { if local_site.federation_enabled { let mut linked = Vec::new(); let mut allowed = Vec::new(); @@ -375,7 +375,7 @@ pub async fn build_federated_instances( } /// Checks the password length -pub fn password_length_check(pass: &str) -> Result<(), LemmyError> { +pub fn password_length_check(pass: &str) -> LemmyResult<()> { if !(10..=60).contains(&pass.chars().count()) { Err(LemmyErrorType::InvalidPassword)? } else { @@ -384,7 +384,7 @@ pub fn password_length_check(pass: &str) -> Result<(), LemmyError> { } /// Checks for a honeypot. If this field is filled, fail the rest of the function -pub fn honeypot_check(honeypot: &Option) -> Result<(), LemmyError> { +pub fn honeypot_check(honeypot: &Option) -> LemmyResult<()> { if honeypot.is_some() && honeypot != &Some(String::new()) { Err(LemmyErrorType::HoneypotFailed)? } else { @@ -422,7 +422,7 @@ pub async fn send_password_reset_email( user: &LocalUserView, pool: &mut DbPool<'_>, settings: &Settings, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { // Generate a random token let token = uuid::Uuid::new_v4().to_string(); @@ -447,7 +447,7 @@ pub async fn send_verification_email( new_email: &str, pool: &mut DbPool<'_>, settings: &Settings, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let form = EmailVerificationForm { local_user_id: user.local_user.id, email: new_email.to_string(), @@ -564,7 +564,7 @@ pub async fn get_url_blocklist(context: &LemmyContext) -> LemmyResult pub async fn send_application_approved_email( user: &LocalUserView, settings: &Settings, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let email = &user.local_user.email.clone().expect("email"); let lang = get_interface_language(user); let subject = lang.registration_approved_subject(&user.person.actor_id); @@ -577,7 +577,7 @@ pub async fn send_new_applicant_email_to_admins( applicant_username: &str, pool: &mut DbPool<'_>, settings: &Settings, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { // Collect the admins with emails let admins = LocalUserView::list_admins_with_emails(pool).await?; @@ -602,7 +602,7 @@ pub async fn send_new_report_email_to_admins( reported_username: &str, pool: &mut DbPool<'_>, settings: &Settings, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { // Collect the admins with emails let admins = LocalUserView::list_admins_with_emails(pool).await?; @@ -618,9 +618,7 @@ pub async fn send_new_report_email_to_admins( Ok(()) } -pub fn check_private_instance_and_federation_enabled( - local_site: &LocalSite, -) -> Result<(), LemmyError> { +pub fn check_private_instance_and_federation_enabled(local_site: &LocalSite) -> LemmyResult<()> { if local_site.private_instance && local_site.federation_enabled { Err(LemmyErrorType::CantEnablePrivateInstanceAndFederationTogether)? } else { @@ -634,7 +632,7 @@ pub fn check_private_instance_and_federation_enabled( pub async fn read_site_for_actor( actor_id: DbUrl, context: &LemmyContext, -) -> Result, LemmyError> { +) -> LemmyResult> { let site_id = Site::instance_actor_id_from_url(actor_id.clone().into()); let site = Site::read_from_apub_id(&mut context.pool(), &site_id.into()).await?; Ok(site) @@ -643,7 +641,7 @@ pub async fn read_site_for_actor( pub async fn purge_image_posts_for_person( banned_person_id: PersonId, context: &LemmyContext, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let pool = &mut context.pool(); let posts = Post::fetch_pictrs_posts_for_creator(pool, banned_person_id).await?; for post in posts { @@ -661,10 +659,7 @@ pub async fn purge_image_posts_for_person( } /// Delete a local_user's images -async fn delete_local_user_images( - person_id: PersonId, - context: &LemmyContext, -) -> Result<(), LemmyError> { +async fn delete_local_user_images(person_id: PersonId, context: &LemmyContext) -> LemmyResult<()> { if let Ok(local_user) = LocalUserView::read_person(&mut context.pool(), person_id).await { let pictrs_uploads = LocalImage::get_all_by_local_user_id(&mut context.pool(), local_user.local_user.id).await?; @@ -682,7 +677,7 @@ async fn delete_local_user_images( pub async fn purge_image_posts_for_community( banned_community_id: CommunityId, context: &LemmyContext, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let pool = &mut context.pool(); let posts = Post::fetch_pictrs_posts_for_community(pool, banned_community_id).await?; for post in posts { @@ -702,7 +697,7 @@ pub async fn purge_image_posts_for_community( pub async fn remove_user_data( banned_person_id: PersonId, context: &LemmyContext, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let pool = &mut context.pool(); // Purge user images let person = Person::read(pool, banned_person_id).await?; @@ -785,7 +780,7 @@ pub async fn remove_user_data_in_community( community_id: CommunityId, banned_person_id: PersonId, pool: &mut DbPool<'_>, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { // Posts Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), true).await?; @@ -815,10 +810,7 @@ pub async fn remove_user_data_in_community( Ok(()) } -pub async fn purge_user_account( - person_id: PersonId, - context: &LemmyContext, -) -> Result<(), LemmyError> { +pub async fn purge_user_account(person_id: PersonId, context: &LemmyContext) -> LemmyResult<()> { let pool = &mut context.pool(); let person = Person::read(pool, person_id).await?; @@ -888,7 +880,7 @@ pub fn generate_inbox_url(actor_id: &DbUrl) -> Result { Ok(Url::parse(&format!("{actor_id}/inbox"))?.into()) } -pub fn generate_shared_inbox_url(settings: &Settings) -> Result { +pub fn generate_shared_inbox_url(settings: &Settings) -> LemmyResult { let url = format!("{}/inbox", settings.get_protocol_and_hostname()); Ok(Url::parse(&url)?.into()) } @@ -901,7 +893,7 @@ pub fn generate_featured_url(actor_id: &DbUrl) -> Result { Ok(Url::parse(&format!("{actor_id}/featured"))?.into()) } -pub fn generate_moderators_url(community_id: &DbUrl) -> Result { +pub fn generate_moderators_url(community_id: &DbUrl) -> LemmyResult { Ok(Url::parse(&format!("{community_id}/moderators"))?.into()) } diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index f8092268f..6b1c4ed30 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -30,7 +30,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, utils::{mention::scrape_text_for_mentions, validation::is_valid_body_field}, }; @@ -41,7 +41,7 @@ pub async fn create_comment( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; let slur_regex = local_site_to_slur_regex(&local_site); @@ -207,7 +207,7 @@ pub async fn create_comment( )) } -pub fn check_comment_depth(comment: &Comment) -> Result<(), LemmyError> { +pub fn check_comment_depth(comment: &Comment) -> LemmyResult<()> { let path = &comment.path.0; let length = path.split('.').count(); if length > MAX_COMMENT_DEPTH_LIMIT { diff --git a/crates/api_crud/src/comment/delete.rs b/crates/api_crud/src/comment/delete.rs index 9db1ed034..00a8ea0c1 100644 --- a/crates/api_crud/src/comment/delete.rs +++ b/crates/api_crud/src/comment/delete.rs @@ -12,14 +12,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::{CommentView, LocalUserView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn delete_comment( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let comment_id = data.comment_id; let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?; diff --git a/crates/api_crud/src/comment/read.rs b/crates/api_crud/src/comment/read.rs index 733d08682..39852081f 100644 --- a/crates/api_crud/src/comment/read.rs +++ b/crates/api_crud/src/comment/read.rs @@ -7,14 +7,14 @@ use lemmy_api_common::{ }; use lemmy_db_schema::source::local_site::LocalSite; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn get_comment( data: Query, context: Data, local_user_view: Option, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; check_private_instance(&local_user_view, &local_site)?; diff --git a/crates/api_crud/src/comment/remove.rs b/crates/api_crud/src/comment/remove.rs index d735c4462..1355a7076 100644 --- a/crates/api_crud/src/comment/remove.rs +++ b/crates/api_crud/src/comment/remove.rs @@ -16,14 +16,14 @@ use lemmy_db_schema::{ traits::{Crud, Reportable}, }; use lemmy_db_views::structs::{CommentView, LocalUserView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn remove_comment( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let comment_id = data.comment_id; let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?; diff --git a/crates/api_crud/src/comment/update.rs b/crates/api_crud/src/comment/update.rs index b35333ec5..ff6f78804 100644 --- a/crates/api_crud/src/comment/update.rs +++ b/crates/api_crud/src/comment/update.rs @@ -23,7 +23,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::{CommentView, LocalUserView}; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, utils::{mention::scrape_text_for_mentions, validation::is_valid_body_field}, }; @@ -32,7 +32,7 @@ pub async fn update_comment( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; let comment_id = data.comment_id; diff --git a/crates/api_crud/src/community/create.rs b/crates/api_crud/src/community/create.rs index 679655078..32d37d8ef 100644 --- a/crates/api_crud/src/community/create.rs +++ b/crates/api_crud/src/community/create.rs @@ -33,7 +33,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, utils::{ slurs::check_slurs, validation::{is_valid_actor_name, is_valid_body_field}, @@ -45,7 +45,7 @@ pub async fn create_community( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let site_view = SiteView::read_local(&mut context.pool()).await?; let local_site = site_view.local_site; diff --git a/crates/api_crud/src/community/delete.rs b/crates/api_crud/src/community/delete.rs index 60b79fd79..a2ceaff50 100644 --- a/crates/api_crud/src/community/delete.rs +++ b/crates/api_crud/src/community/delete.rs @@ -13,14 +13,14 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::CommunityModeratorView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn delete_community( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Fetch the community mods let community_id = data.community_id; let community_mods = diff --git a/crates/api_crud/src/community/list.rs b/crates/api_crud/src/community/list.rs index 7990352fc..9c13ae89f 100644 --- a/crates/api_crud/src/community/list.rs +++ b/crates/api_crud/src/community/list.rs @@ -6,14 +6,14 @@ use lemmy_api_common::{ }; use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_db_views_actor::community_view::CommunityQuery; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn list_communities( data: Query, context: Data, local_user_view: Option, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = SiteView::read_local(&mut context.pool()).await?; let is_admin = local_user_view .as_ref() diff --git a/crates/api_crud/src/community/remove.rs b/crates/api_crud/src/community/remove.rs index d7be60927..f4271565d 100644 --- a/crates/api_crud/src/community/remove.rs +++ b/crates/api_crud/src/community/remove.rs @@ -15,14 +15,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn remove_community( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { check_community_mod_action( &local_user_view.person, data.community_id, diff --git a/crates/api_crud/src/community/update.rs b/crates/api_crud/src/community/update.rs index 51c57e1c8..bc0945ba1 100644 --- a/crates/api_crud/src/community/update.rs +++ b/crates/api_crud/src/community/update.rs @@ -25,7 +25,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, utils::{slurs::check_slurs_opt, validation::is_valid_body_field}, }; @@ -34,7 +34,7 @@ pub async fn update_community( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; let slur_regex = local_site_to_slur_regex(&local_site); diff --git a/crates/api_crud/src/custom_emoji/create.rs b/crates/api_crud/src/custom_emoji/create.rs index cd30ef1e9..3c5ce3296 100644 --- a/crates/api_crud/src/custom_emoji/create.rs +++ b/crates/api_crud/src/custom_emoji/create.rs @@ -11,14 +11,14 @@ use lemmy_db_schema::source::{ local_site::LocalSite, }; use lemmy_db_views::structs::{CustomEmojiView, LocalUserView}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn create_custom_emoji( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; // Make sure user is an admin is_admin(&local_user_view)?; diff --git a/crates/api_crud/src/custom_emoji/delete.rs b/crates/api_crud/src/custom_emoji/delete.rs index 93c5f8d80..45ac8d0ba 100644 --- a/crates/api_crud/src/custom_emoji/delete.rs +++ b/crates/api_crud/src/custom_emoji/delete.rs @@ -8,14 +8,14 @@ use lemmy_api_common::{ }; use lemmy_db_schema::source::custom_emoji::CustomEmoji; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn delete_custom_emoji( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Make sure user is an admin is_admin(&local_user_view)?; diff --git a/crates/api_crud/src/custom_emoji/update.rs b/crates/api_crud/src/custom_emoji/update.rs index 5a2631a62..63246f85d 100644 --- a/crates/api_crud/src/custom_emoji/update.rs +++ b/crates/api_crud/src/custom_emoji/update.rs @@ -11,14 +11,14 @@ use lemmy_db_schema::source::{ local_site::LocalSite, }; use lemmy_db_views::structs::{CustomEmojiView, LocalUserView}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn update_custom_emoji( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; // Make sure user is an admin is_admin(&local_user_view)?; diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 6a61c032b..cea0d5a31 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -32,7 +32,7 @@ use lemmy_db_schema::{ use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::CommunityModeratorView; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, spawn_try_task, utils::{ slurs::check_slurs, @@ -55,7 +55,7 @@ pub async fn create_post( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; honeypot_check(&data.honeypot)?; diff --git a/crates/api_crud/src/post/delete.rs b/crates/api_crud/src/post/delete.rs index a8fce28fc..e07ff7723 100644 --- a/crates/api_crud/src/post/delete.rs +++ b/crates/api_crud/src/post/delete.rs @@ -12,14 +12,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn delete_post( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let post_id = data.post_id; let orig_post = Post::read(&mut context.pool(), post_id).await?; diff --git a/crates/api_crud/src/post/read.rs b/crates/api_crud/src/post/read.rs index e701008b7..cb4ba7e9f 100644 --- a/crates/api_crud/src/post/read.rs +++ b/crates/api_crud/src/post/read.rs @@ -14,14 +14,14 @@ use lemmy_db_views::{ structs::{LocalUserView, PostView, SiteView}, }; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn get_post( data: Query, context: Data, local_user_view: Option, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = SiteView::read_local(&mut context.pool()).await?; check_private_instance(&local_user_view, &local_site.local_site)?; diff --git a/crates/api_crud/src/post/remove.rs b/crates/api_crud/src/post/remove.rs index cbcf069b6..37f3f6148 100644 --- a/crates/api_crud/src/post/remove.rs +++ b/crates/api_crud/src/post/remove.rs @@ -16,14 +16,14 @@ use lemmy_db_schema::{ traits::{Crud, Reportable}, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn remove_post( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let post_id = data.post_id; let orig_post = Post::read(&mut context.pool(), post_id).await?; diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index c08f35307..48a1b6523 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -25,7 +25,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, utils::{ slurs::check_slurs_opt, validation::{ @@ -45,7 +45,7 @@ pub async fn update_post( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; // TODO No good way to handle a clear. diff --git a/crates/api_crud/src/private_message/create.rs b/crates/api_crud/src/private_message/create.rs index 32d8b99e6..1fe4f9b48 100644 --- a/crates/api_crud/src/private_message/create.rs +++ b/crates/api_crud/src/private_message/create.rs @@ -24,7 +24,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, utils::{markdown::markdown_to_html, validation::is_valid_body_field}, }; @@ -33,7 +33,7 @@ pub async fn create_private_message( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; let slur_regex = local_site_to_slur_regex(&local_site); diff --git a/crates/api_crud/src/private_message/delete.rs b/crates/api_crud/src/private_message/delete.rs index ef0864d70..936ff57b8 100644 --- a/crates/api_crud/src/private_message/delete.rs +++ b/crates/api_crud/src/private_message/delete.rs @@ -10,14 +10,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn delete_private_message( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { // Checking permissions let private_message_id = data.private_message_id; let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?; diff --git a/crates/api_crud/src/private_message/read.rs b/crates/api_crud/src/private_message/read.rs index 9f289c911..7558b97fc 100644 --- a/crates/api_crud/src/private_message/read.rs +++ b/crates/api_crud/src/private_message/read.rs @@ -4,14 +4,14 @@ use lemmy_api_common::{ private_message::{GetPrivateMessages, PrivateMessagesResponse}, }; use lemmy_db_views::{private_message_view::PrivateMessageQuery, structs::LocalUserView}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn get_private_message( data: Query, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let person_id = local_user_view.person.id; let page = data.page; diff --git a/crates/api_crud/src/private_message/update.rs b/crates/api_crud/src/private_message/update.rs index 29063fd10..765a33053 100644 --- a/crates/api_crud/src/private_message/update.rs +++ b/crates/api_crud/src/private_message/update.rs @@ -16,7 +16,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, utils::validation::is_valid_body_field, }; @@ -25,7 +25,7 @@ pub async fn update_private_message( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; // Checking permissions diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index 8542117e7..1c2fed3ed 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -27,7 +27,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_utils::{ - error::{LemmyError, LemmyErrorType, LemmyResult}, + error::{LemmyErrorType, LemmyResult}, utils::{ slurs::{check_slurs, check_slurs_opt}, validation::{ @@ -46,7 +46,7 @@ pub async fn create_site( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; // Make sure user is an admin; other types of users should not create site data... diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index c4b27de1e..c8ad866a3 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -19,7 +19,7 @@ use lemmy_db_views_actor::structs::{ PersonView, }; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult}, CACHE_DURATION_API, VERSION, }; @@ -30,7 +30,7 @@ use once_cell::sync::Lazy; pub async fn get_site( local_user_view: Option, context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { static CACHE: Lazy> = Lazy::new(|| { Cache::builder() .max_capacity(1) diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index 530dbb47f..adf44fad4 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -32,7 +32,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, utils::{ slurs::check_slurs_opt, validation::{ @@ -51,7 +51,7 @@ pub async fn update_site( data: Json, context: Data, local_user_view: LocalUserView, -) -> Result, LemmyError> { +) -> LemmyResult> { let site_view = SiteView::read_local(&mut context.pool()).await?; let local_site = site_view.local_site; let site = site_view.site; diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index d24a287db..1f81d4324 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -31,7 +31,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, utils::{ slurs::{check_slurs, check_slurs_opt}, validation::is_valid_actor_name, @@ -44,7 +44,7 @@ pub async fn register( data: Json, req: HttpRequest, context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { let site_view = SiteView::read_local(&mut context.pool()).await?; let local_site = site_view.local_site; let require_registration_application = diff --git a/crates/apub/src/activities/block/block_user.rs b/crates/apub/src/activities/block/block_user.rs index a2a1f25bf..f68301be1 100644 --- a/crates/apub/src/activities/block/block_user.rs +++ b/crates/apub/src/activities/block/block_user.rs @@ -39,7 +39,7 @@ use lemmy_db_schema::{ }, traits::{Bannable, Crud, Followable}, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; impl BlockUser { @@ -51,7 +51,7 @@ impl BlockUser { reason: Option, expires: Option>, context: &Data, - ) -> Result { + ) -> LemmyResult { let audience = if let SiteOrCommunity::Community(c) = target { Some(c.id().into()) } else { @@ -85,7 +85,7 @@ impl BlockUser { reason: Option, expires: Option>, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let block = BlockUser::new( target, user, @@ -125,7 +125,7 @@ impl ActivityHandler for BlockUser { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_is_public(&self.to, &self.cc)?; match self.target.dereference(context).await? { SiteOrCommunity::Site(site) => { @@ -148,7 +148,7 @@ impl ActivityHandler for BlockUser { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let expires = self.expires.or(self.end_time).map(Into::into); let mod_person = self.actor.dereference(context).await?; diff --git a/crates/apub/src/activities/block/mod.rs b/crates/apub/src/activities/block/mod.rs index 92fea4ec5..51d8bf5e0 100644 --- a/crates/apub/src/activities/block/mod.rs +++ b/crates/apub/src/activities/block/mod.rs @@ -58,10 +58,7 @@ impl Object for SiteOrCommunity { } #[tracing::instrument(skip_all)] - async fn read_from_id( - object_id: Url, - data: &Data, - ) -> Result, LemmyError> + async fn read_from_id(object_id: Url, data: &Data) -> LemmyResult> where Self: Sized, { @@ -74,11 +71,11 @@ impl Object for SiteOrCommunity { }) } - async fn delete(self, _data: &Data) -> Result<(), LemmyError> { + async fn delete(self, _data: &Data) -> LemmyResult<()> { unimplemented!() } - async fn into_json(self, _data: &Data) -> Result { + async fn into_json(self, _data: &Data) -> LemmyResult { unimplemented!() } @@ -87,7 +84,7 @@ impl Object for SiteOrCommunity { apub: &Self::Kind, expected_domain: &Url, data: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { match apub { InstanceOrGroup::Instance(i) => ApubSite::verify(i, expected_domain, data).await, InstanceOrGroup::Group(g) => ApubCommunity::verify(g, expected_domain, data).await, @@ -95,7 +92,7 @@ impl Object for SiteOrCommunity { } #[tracing::instrument(skip_all)] - async fn from_json(apub: Self::Kind, data: &Data) -> Result + async fn from_json(apub: Self::Kind, data: &Data) -> LemmyResult where Self: Sized, { @@ -117,10 +114,7 @@ impl SiteOrCommunity { } } -async fn generate_cc( - target: &SiteOrCommunity, - pool: &mut DbPool<'_>, -) -> Result, LemmyError> { +async fn generate_cc(target: &SiteOrCommunity, pool: &mut DbPool<'_>) -> LemmyResult> { Ok(match target { SiteOrCommunity::Site(_) => Site::read_remote_sites(pool) .await? @@ -139,7 +133,7 @@ pub(crate) async fn send_ban_from_site( ban: bool, expires: Option, context: Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let site = SiteOrCommunity::Site(SiteView::read_local(&mut context.pool()).await?.site.into()); let expires = check_expire_time(expires)?; diff --git a/crates/apub/src/activities/block/undo_block_user.rs b/crates/apub/src/activities/block/undo_block_user.rs index 756d0a149..b92320b2d 100644 --- a/crates/apub/src/activities/block/undo_block_user.rs +++ b/crates/apub/src/activities/block/undo_block_user.rs @@ -27,7 +27,7 @@ use lemmy_db_schema::{ }, traits::{Bannable, Crud}, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; impl UndoBlockUser { @@ -38,7 +38,7 @@ impl UndoBlockUser { mod_: &ApubPerson, reason: Option, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let block = BlockUser::new(target, user, mod_, None, reason, None, context).await?; let audience = if let SiteOrCommunity::Community(c) = target { Some(c.id().into()) @@ -88,7 +88,7 @@ impl ActivityHandler for UndoBlockUser { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_is_public(&self.to, &self.cc)?; verify_domains_match(self.actor.inner(), self.object.actor.inner())?; self.object.verify(context).await?; @@ -96,7 +96,7 @@ impl ActivityHandler for UndoBlockUser { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let expires = self.object.expires.or(self.object.end_time).map(Into::into); let mod_person = self.actor.dereference(context).await?; diff --git a/crates/apub/src/activities/community/announce.rs b/crates/apub/src/activities/community/announce.rs index 474afc3b9..9a3928882 100644 --- a/crates/apub/src/activities/community/announce.rs +++ b/crates/apub/src/activities/community/announce.rs @@ -82,7 +82,7 @@ impl AnnounceActivity { object: RawAnnouncableActivities, community: &ApubCommunity, context: &Data, - ) -> Result { + ) -> LemmyResult { let inner_kind = object .other .get("type") @@ -105,7 +105,7 @@ impl AnnounceActivity { object: RawAnnouncableActivities, community: &ApubCommunity, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let announce = AnnounceActivity::new(object.clone(), community, context)?; let inboxes = ActivitySendTargets::to_local_community_followers(community.id); send_lemmy_activity(context, announce, community, inboxes.clone(), false).await?; @@ -148,13 +148,13 @@ impl ActivityHandler for AnnounceActivity { } #[tracing::instrument(skip_all)] - async fn verify(&self, _context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, _context: &Data) -> LemmyResult<()> { verify_is_public(&self.to, &self.cc)?; Ok(()) } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let object: AnnouncableActivities = self.object.object(context).await?.try_into()?; diff --git a/crates/apub/src/activities/community/collection_add.rs b/crates/apub/src/activities/community/collection_add.rs index fdd62bdb1..34c46cf6b 100644 --- a/crates/apub/src/activities/community/collection_add.rs +++ b/crates/apub/src/activities/community/collection_add.rs @@ -36,7 +36,7 @@ use lemmy_db_schema::{ }, traits::{Crud, Joinable}, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; impl CollectionAdd { @@ -46,7 +46,7 @@ impl CollectionAdd { added_mod: &ApubPerson, actor: &ApubPerson, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let id = generate_activity_id( AddType::Add, &context.settings().get_protocol_and_hostname(), @@ -72,7 +72,7 @@ impl CollectionAdd { featured_post: &ApubPost, actor: &ApubPerson, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let id = generate_activity_id( AddType::Add, &context.settings().get_protocol_and_hostname(), @@ -114,7 +114,7 @@ impl ActivityHandler for CollectionAdd { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_is_public(&self.to, &self.cc)?; let community = self.community(context).await?; verify_person_in_community(&self.actor, &community, context).await?; @@ -123,7 +123,7 @@ impl ActivityHandler for CollectionAdd { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let (community, collection_type) = Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?; @@ -179,7 +179,7 @@ pub(crate) async fn send_add_mod_to_community( updated_mod_id: PersonId, added: bool, context: Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let actor: ApubPerson = actor.into(); let community: ApubCommunity = Community::read(&mut context.pool(), community_id) .await? @@ -199,7 +199,7 @@ pub(crate) async fn send_feature_post( actor: Person, featured: bool, context: Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let actor: ApubPerson = actor.into(); let post: ApubPost = post.into(); let community = Community::read(&mut context.pool(), post.community_id) diff --git a/crates/apub/src/activities/community/collection_remove.rs b/crates/apub/src/activities/community/collection_remove.rs index 06238a890..90df1fd14 100644 --- a/crates/apub/src/activities/community/collection_remove.rs +++ b/crates/apub/src/activities/community/collection_remove.rs @@ -31,7 +31,7 @@ use lemmy_db_schema::{ }, traits::{Crud, Joinable}, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; impl CollectionRemove { @@ -41,7 +41,7 @@ impl CollectionRemove { removed_mod: &ApubPerson, actor: &ApubPerson, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let id = generate_activity_id( RemoveType::Remove, &context.settings().get_protocol_and_hostname(), @@ -67,7 +67,7 @@ impl CollectionRemove { featured_post: &ApubPost, actor: &ApubPerson, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let id = generate_activity_id( RemoveType::Remove, &context.settings().get_protocol_and_hostname(), @@ -109,7 +109,7 @@ impl ActivityHandler for CollectionRemove { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_is_public(&self.to, &self.cc)?; let community = self.community(context).await?; verify_person_in_community(&self.actor, &community, context).await?; @@ -118,7 +118,7 @@ impl ActivityHandler for CollectionRemove { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let (community, collection_type) = Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?; diff --git a/crates/apub/src/activities/community/lock_page.rs b/crates/apub/src/activities/community/lock_page.rs index db9dfa36c..ba3e16417 100644 --- a/crates/apub/src/activities/community/lock_page.rs +++ b/crates/apub/src/activities/community/lock_page.rs @@ -31,7 +31,7 @@ use lemmy_db_schema::{ }, traits::Crud, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; #[async_trait::async_trait] @@ -106,7 +106,7 @@ pub(crate) async fn send_lock_post( actor: Person, locked: bool, context: Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let community: ApubCommunity = Community::read(&mut context.pool(), post.community_id) .await? .into(); diff --git a/crates/apub/src/activities/community/mod.rs b/crates/apub/src/activities/community/mod.rs index 612fd8a7a..a47dec2bd 100644 --- a/crates/apub/src/activities/community/mod.rs +++ b/crates/apub/src/activities/community/mod.rs @@ -10,7 +10,7 @@ use lemmy_db_schema::{ source::{activity::ActivitySendTargets, person::PersonFollower}, CommunityVisibility, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; pub mod announce; pub mod collection_add; @@ -39,7 +39,7 @@ pub(crate) async fn send_activity_in_community( extra_inboxes: ActivitySendTargets, is_mod_action: bool, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { // If community is local only, don't send anything out if community.visibility != CommunityVisibility::Public { return Ok(()); diff --git a/crates/apub/src/activities/community/report.rs b/crates/apub/src/activities/community/report.rs index 6b1fce066..4966add34 100644 --- a/crates/apub/src/activities/community/report.rs +++ b/crates/apub/src/activities/community/report.rs @@ -29,7 +29,7 @@ use lemmy_db_schema::{ }, traits::{Crud, Reportable}, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; impl Report { @@ -40,7 +40,7 @@ impl Report { community: Community, reason: String, context: Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let actor: ApubPerson = actor.into(); let community: ApubCommunity = community.into(); let kind = FlagType::Flag; @@ -94,14 +94,14 @@ impl ActivityHandler for Report { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { let community = self.community(context).await?; verify_person_in_community(&self.actor, &community, context).await?; Ok(()) } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let actor = self.actor.dereference(context).await?; let reason = self.reason()?; diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index ca293d002..3457e6c24 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -26,14 +26,14 @@ use lemmy_db_schema::{ traits::Crud, utils::naive_now, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; pub(crate) async fn send_update_community( community: Community, actor: Person, context: Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let community: ApubCommunity = community.into(); let actor: ApubPerson = actor.into(); let id = generate_activity_id( @@ -76,7 +76,7 @@ impl ActivityHandler for UpdateCommunity { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_is_public(&self.to, &self.cc)?; let community = self.community(context).await?; verify_person_in_community(&self.actor, &community, context).await?; @@ -86,7 +86,7 @@ impl ActivityHandler for UpdateCommunity { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let community = self.community(context).await?; diff --git a/crates/apub/src/activities/create_or_update/comment.rs b/crates/apub/src/activities/create_or_update/comment.rs index ea6af2fcf..8fbbe42b3 100644 --- a/crates/apub/src/activities/create_or_update/comment.rs +++ b/crates/apub/src/activities/create_or_update/comment.rs @@ -39,7 +39,10 @@ use lemmy_db_schema::{ }, traits::{Crud, Likeable}, }; -use lemmy_utils::{error::LemmyError, utils::mention::scrape_text_for_mentions}; +use lemmy_utils::{ + error::{LemmyError, LemmyResult}, + utils::mention::scrape_text_for_mentions, +}; use url::Url; impl CreateOrUpdateNote { @@ -49,7 +52,7 @@ impl CreateOrUpdateNote { person_id: PersonId, kind: CreateOrUpdateType, context: Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { // TODO: might be helpful to add a comment method to retrieve community directly let post_id = comment.post_id; let post = Post::read(&mut context.pool(), post_id).await?; @@ -114,7 +117,7 @@ impl ActivityHandler for CreateOrUpdateNote { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_is_public(&self.to, &self.cc)?; let post = self.object.get_parents(context).await?.0; let community = self.community(context).await?; @@ -129,7 +132,7 @@ impl ActivityHandler for CreateOrUpdateNote { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; // Need to do this check here instead of Note::from_json because we need the person who // send the activity, not the comment author. diff --git a/crates/apub/src/activities/create_or_update/post.rs b/crates/apub/src/activities/create_or_update/post.rs index 8b2fdbdb4..eb59e054a 100644 --- a/crates/apub/src/activities/create_or_update/post.rs +++ b/crates/apub/src/activities/create_or_update/post.rs @@ -33,7 +33,7 @@ use lemmy_db_schema::{ }, traits::{Crud, Likeable}, }; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult}; use url::Url; impl CreateOrUpdatePage { @@ -43,7 +43,7 @@ impl CreateOrUpdatePage { community: &ApubCommunity, kind: CreateOrUpdateType, context: &Data, - ) -> Result { + ) -> LemmyResult { let id = generate_activity_id( kind.clone(), &context.settings().get_protocol_and_hostname(), @@ -65,7 +65,7 @@ impl CreateOrUpdatePage { person_id: PersonId, kind: CreateOrUpdateType, context: Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let post = ApubPost(post); let community_id = post.community_id; let person: ApubPerson = Person::read(&mut context.pool(), person_id).await?.into(); @@ -104,7 +104,7 @@ impl ActivityHandler for CreateOrUpdatePage { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_is_public(&self.to, &self.cc)?; let community = self.community(context).await?; verify_person_in_community(&self.actor, &community, context).await?; @@ -138,7 +138,7 @@ impl ActivityHandler for CreateOrUpdatePage { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let post = ApubPost::from_json(self.object, context).await?; diff --git a/crates/apub/src/activities/create_or_update/private_message.rs b/crates/apub/src/activities/create_or_update/private_message.rs index f3ea3ca26..950f4ae99 100644 --- a/crates/apub/src/activities/create_or_update/private_message.rs +++ b/crates/apub/src/activities/create_or_update/private_message.rs @@ -15,14 +15,14 @@ use activitypub_federation::{ use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::source::activity::ActivitySendTargets; use lemmy_db_views::structs::PrivateMessageView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; pub(crate) async fn send_create_or_update_pm( pm_view: PrivateMessageView, kind: CreateOrUpdateType, context: Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let actor: ApubPerson = pm_view.creator.into(); let recipient: ApubPerson = pm_view.recipient.into(); @@ -57,7 +57,7 @@ impl ActivityHandler for CreateOrUpdateChatMessage { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_person(&self.actor, context).await?; verify_domains_match(self.actor.inner(), self.object.id.inner())?; verify_domains_match(self.to[0].inner(), self.object.to[0].inner())?; @@ -66,7 +66,7 @@ impl ActivityHandler for CreateOrUpdateChatMessage { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; ApubPrivateMessage::from_json(self.object, context).await?; Ok(()) diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index 18f8cf6fb..cecc051b4 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -27,7 +27,7 @@ use lemmy_db_schema::{ }, traits::{Crud, Reportable}, }; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult}; use url::Url; #[async_trait::async_trait] @@ -44,13 +44,13 @@ impl ActivityHandler for Delete { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_delete_activity(self, self.summary.is_some(), context).await?; Ok(()) } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; if let Some(reason) = self.summary { // We set reason to empty string if it doesn't exist, to distinguish between delete and @@ -88,7 +88,7 @@ impl Delete { community: Option<&Community>, summary: Option, context: &Data, - ) -> Result { + ) -> LemmyResult { let id = generate_activity_id( DeleteType::Delete, &context.settings().get_protocol_and_hostname(), @@ -114,7 +114,7 @@ pub(in crate::activities) async fn receive_remove_action( object: &Url, reason: Option, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { match DeletableObjects::read_from_db(object, context).await? { DeletableObjects::Community(community) => { if community.local { diff --git a/crates/apub/src/activities/deletion/mod.rs b/crates/apub/src/activities/deletion/mod.rs index 03f01a3b9..b12532087 100644 --- a/crates/apub/src/activities/deletion/mod.rs +++ b/crates/apub/src/activities/deletion/mod.rs @@ -39,7 +39,7 @@ use lemmy_db_schema::{ }, traits::Crud, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use std::ops::Deref; use url::Url; @@ -56,7 +56,7 @@ pub(crate) async fn send_apub_delete_in_community( reason: Option, deleted: bool, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let actor = ApubPerson::from(actor); let is_mod_action = reason.is_some(); let activity = if deleted { @@ -83,7 +83,7 @@ pub(crate) async fn send_apub_delete_private_message( pm: PrivateMessage, deleted: bool, context: Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let recipient_id = pm.recipient_id; let recipient: ApubPerson = Person::read(&mut context.pool(), recipient_id) .await? @@ -105,7 +105,7 @@ pub async fn send_apub_delete_user( person: Person, remove_data: bool, context: Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let person: ApubPerson = person.into(); let deletable = DeletableObjects::Person(person.clone()); @@ -131,7 +131,7 @@ impl DeletableObjects { pub(crate) async fn read_from_db( ap_id: &Url, context: &Data, - ) -> Result { + ) -> LemmyResult { if let Some(c) = ApubCommunity::read_from_id(ap_id.clone(), context).await? { return Ok(DeletableObjects::Community(c)); } @@ -166,7 +166,7 @@ pub(in crate::activities) async fn verify_delete_activity( activity: &Delete, is_mod_action: bool, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let object = DeletableObjects::read_from_db(activity.object.id(), context).await?; match object { DeletableObjects::Community(community) => { @@ -221,7 +221,7 @@ async fn verify_delete_post_or_comment( community: &ApubCommunity, is_mod_action: bool, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { verify_person_in_community(actor, community, context).await?; if is_mod_action { verify_mod_action(actor, community, context).await?; @@ -240,7 +240,7 @@ async fn receive_delete_action( deleted: bool, do_purge_user_account: Option, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { match DeletableObjects::read_from_db(object, context).await? { DeletableObjects::Community(community) => { if community.local { diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index 558d72b57..4f0fad670 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -25,7 +25,7 @@ use lemmy_db_schema::{ }, traits::Crud, }; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult}; use url::Url; #[async_trait::async_trait] @@ -48,7 +48,7 @@ impl ActivityHandler for UndoDelete { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; if self.object.summary.is_some() { UndoDelete::receive_undo_remove_action( @@ -72,7 +72,7 @@ impl UndoDelete { community: Option<&Community>, summary: Option, context: &Data, - ) -> Result { + ) -> LemmyResult { let object = Delete::new(actor, object, to.clone(), community, summary, context)?; let id = generate_activity_id( @@ -96,7 +96,7 @@ impl UndoDelete { actor: &ApubPerson, object: &Url, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { match DeletableObjects::read_from_db(object, context).await? { DeletableObjects::Community(community) => { if community.local { diff --git a/crates/apub/src/activities/following/accept.rs b/crates/apub/src/activities/following/accept.rs index efecef7f1..fa711b904 100644 --- a/crates/apub/src/activities/following/accept.rs +++ b/crates/apub/src/activities/following/accept.rs @@ -14,12 +14,12 @@ use lemmy_db_schema::{ source::{activity::ActivitySendTargets, community::CommunityFollower}, traits::Followable, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; impl AcceptFollow { #[tracing::instrument(skip_all)] - pub async fn send(follow: Follow, context: &Data) -> Result<(), LemmyError> { + pub async fn send(follow: Follow, context: &Data) -> LemmyResult<()> { let user_or_community = follow.object.dereference_local(context).await?; let person = follow.actor.clone().dereference(context).await?; let accept = AcceptFollow { @@ -52,7 +52,7 @@ impl ActivityHandler for AcceptFollow { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_urls_match(self.actor.inner(), self.object.object.inner())?; self.object.verify(context).await?; if let Some(to) = &self.to { @@ -62,7 +62,7 @@ impl ActivityHandler for AcceptFollow { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let community = self.actor.dereference(context).await?; let person = self.object.actor.dereference(context).await?; diff --git a/crates/apub/src/activities/following/follow.rs b/crates/apub/src/activities/following/follow.rs index 6b954ebf2..97227835a 100644 --- a/crates/apub/src/activities/following/follow.rs +++ b/crates/apub/src/activities/following/follow.rs @@ -26,7 +26,7 @@ use lemmy_db_schema::{ traits::Followable, CommunityVisibility, }; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult}; use url::Url; impl Follow { @@ -34,7 +34,7 @@ impl Follow { actor: &ApubPerson, community: &ApubCommunity, context: &Data, - ) -> Result { + ) -> LemmyResult { Ok(Follow { actor: actor.id().into(), object: community.id().into(), @@ -52,7 +52,7 @@ impl Follow { actor: &ApubPerson, community: &ApubCommunity, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let follow = Follow::new(actor, community, context)?; let inbox = if community.local { ActivitySendTargets::empty() @@ -77,7 +77,7 @@ impl ActivityHandler for Follow { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_person(&self.actor, context).await?; let object = self.object.dereference(context).await?; if let UserOrCommunity::Community(c) = object { @@ -90,7 +90,7 @@ impl ActivityHandler for Follow { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let actor = self.actor.dereference(context).await?; let object = self.object.dereference(context).await?; diff --git a/crates/apub/src/activities/following/mod.rs b/crates/apub/src/activities/following/mod.rs index c4f0bd0b7..7c7163f12 100644 --- a/crates/apub/src/activities/following/mod.rs +++ b/crates/apub/src/activities/following/mod.rs @@ -5,7 +5,7 @@ use crate::{ use activitypub_federation::config::Data; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::source::{community::Community, person::Person}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; pub mod accept; pub mod follow; @@ -16,7 +16,7 @@ pub async fn send_follow_community( person: Person, follow: bool, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let community: ApubCommunity = community.into(); let actor: ApubPerson = person.into(); if follow { diff --git a/crates/apub/src/activities/following/undo_follow.rs b/crates/apub/src/activities/following/undo_follow.rs index 90dd452f2..ba6253946 100644 --- a/crates/apub/src/activities/following/undo_follow.rs +++ b/crates/apub/src/activities/following/undo_follow.rs @@ -20,7 +20,7 @@ use lemmy_db_schema::{ }, traits::Followable, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; impl UndoFollow { @@ -29,7 +29,7 @@ impl UndoFollow { actor: &ApubPerson, community: &ApubCommunity, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let object = Follow::new(actor, community, context)?; let undo = UndoFollow { actor: actor.id().into(), @@ -64,7 +64,7 @@ impl ActivityHandler for UndoFollow { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { verify_urls_match(self.actor.inner(), self.object.actor.inner())?; verify_person(&self.actor, context).await?; self.object.verify(context).await?; @@ -75,7 +75,7 @@ impl ActivityHandler for UndoFollow { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let person = self.actor.dereference(context).await?; let object = self.object.object.dereference(context).await?; diff --git a/crates/apub/src/activities/mod.rs b/crates/apub/src/activities/mod.rs index 1472d6866..6547b957d 100644 --- a/crates/apub/src/activities/mod.rs +++ b/crates/apub/src/activities/mod.rs @@ -61,7 +61,7 @@ pub mod voting; async fn verify_person( person_id: &ObjectId, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let person = person_id.dereference(context).await?; if person.banned { Err(anyhow!("Person {} is banned", person_id)) @@ -78,7 +78,7 @@ pub(crate) async fn verify_person_in_community( person_id: &ObjectId, community: &ApubCommunity, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let person = person_id.dereference(context).await?; if person.banned { Err(LemmyErrorType::PersonIsBannedFromSite( @@ -105,7 +105,7 @@ pub(crate) async fn verify_mod_action( mod_id: &ObjectId, community: &Community, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let mod_ = mod_id.dereference(context).await?; let is_mod_or_admin = @@ -124,7 +124,7 @@ pub(crate) async fn verify_mod_action( Err(LemmyErrorType::NotAModerator)? } -pub(crate) fn verify_is_public(to: &[Url], cc: &[Url]) -> Result<(), LemmyError> { +pub(crate) fn verify_is_public(to: &[Url], cc: &[Url]) -> LemmyResult<()> { if ![to, cc].iter().any(|set| set.contains(&public())) { Err(LemmyErrorType::ObjectIsNotPublic)? } else { @@ -132,10 +132,7 @@ pub(crate) fn verify_is_public(to: &[Url], cc: &[Url]) -> Result<(), LemmyError> } } -pub(crate) fn verify_community_matches( - a: &ObjectId, - b: T, -) -> Result<(), LemmyError> +pub(crate) fn verify_community_matches(a: &ObjectId, b: T) -> LemmyResult<()> where T: Into>, { @@ -147,7 +144,7 @@ where } } -pub(crate) fn check_community_deleted_or_removed(community: &Community) -> Result<(), LemmyError> { +pub(crate) fn check_community_deleted_or_removed(community: &Community) -> LemmyResult<()> { if community.deleted || community.removed { Err(LemmyErrorType::CannotCreatePostOrCommentInDeletedOrRemovedCommunity)? } else { @@ -196,7 +193,7 @@ async fn send_lemmy_activity( actor: &ActorT, send_targets: ActivitySendTargets, sensitive: bool, -) -> Result<(), LemmyError> +) -> LemmyResult<()> where Activity: ActivityHandler + Serialize + Send + Sync + Clone, ActorT: Actor + GetActorType, diff --git a/crates/apub/src/activities/voting/mod.rs b/crates/apub/src/activities/voting/mod.rs index 0f9876f1a..2022252c1 100644 --- a/crates/apub/src/activities/voting/mod.rs +++ b/crates/apub/src/activities/voting/mod.rs @@ -21,7 +21,7 @@ use lemmy_db_schema::{ }, traits::Likeable, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; pub mod undo_vote; pub mod vote; @@ -32,7 +32,7 @@ pub(crate) async fn send_like_activity( community: Community, score: i16, context: Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let object_id: ObjectId = object_id.into(); let actor: ApubPerson = actor.into(); let community: ApubCommunity = community.into(); @@ -58,7 +58,7 @@ async fn vote_comment( actor: ApubPerson, comment: &ApubComment, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let comment_id = comment.id; let like_form = CommentLikeForm { comment_id, @@ -78,7 +78,7 @@ async fn vote_post( actor: ApubPerson, post: &ApubPost, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let post_id = post.id; let like_form = PostLikeForm { post_id: post.id, @@ -96,7 +96,7 @@ async fn undo_vote_comment( actor: ApubPerson, comment: &ApubComment, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let comment_id = comment.id; let person_id = actor.id; CommentLike::remove(&mut context.pool(), person_id, comment_id).await?; @@ -108,7 +108,7 @@ async fn undo_vote_post( actor: ApubPerson, post: &ApubPost, context: &Data, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let post_id = post.id; let person_id = actor.id; PostLike::remove(&mut context.pool(), person_id, post_id).await?; diff --git a/crates/apub/src/activities/voting/undo_vote.rs b/crates/apub/src/activities/voting/undo_vote.rs index f83055620..61875d442 100644 --- a/crates/apub/src/activities/voting/undo_vote.rs +++ b/crates/apub/src/activities/voting/undo_vote.rs @@ -19,7 +19,7 @@ use activitypub_federation::{ traits::{ActivityHandler, Actor}, }; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; impl UndoVote { @@ -28,7 +28,7 @@ impl UndoVote { actor: &ApubPerson, community: &ApubCommunity, context: &Data, - ) -> Result { + ) -> LemmyResult { Ok(UndoVote { actor: actor.id().into(), object: vote, @@ -56,7 +56,7 @@ impl ActivityHandler for UndoVote { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { let community = self.community(context).await?; verify_person_in_community(&self.actor, &community, context).await?; verify_urls_match(self.actor.inner(), self.object.actor.inner())?; @@ -65,7 +65,7 @@ impl ActivityHandler for UndoVote { } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let actor = self.actor.dereference(context).await?; let object = self.object.object.dereference(context).await?; diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index 5625ea6ba..324c8b300 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -19,7 +19,7 @@ use activitypub_federation::{ }; use lemmy_api_common::{context::LemmyContext, utils::check_bot_account}; use lemmy_db_schema::source::local_site::LocalSite; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; impl Vote { @@ -29,7 +29,7 @@ impl Vote { community: &ApubCommunity, kind: VoteType, context: &Data, - ) -> Result { + ) -> LemmyResult { Ok(Vote { actor: actor.id().into(), object: object_id, @@ -54,14 +54,14 @@ impl ActivityHandler for Vote { } #[tracing::instrument(skip_all)] - async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + async fn verify(&self, context: &Data) -> LemmyResult<()> { let community = self.community(context).await?; verify_person_in_community(&self.actor, &community, context).await?; Ok(()) } #[tracing::instrument(skip_all)] - async fn receive(self, context: &Data) -> Result<(), LemmyError> { + async fn receive(self, context: &Data) -> LemmyResult<()> { insert_received_activity(&self.id, context).await?; let actor = self.actor.dereference(context).await?; let object = self.object.dereference(context).await?; diff --git a/crates/apub/src/activity_lists.rs b/crates/apub/src/activity_lists.rs index 7b33499c8..3aeb7e45e 100644 --- a/crates/apub/src/activity_lists.rs +++ b/crates/apub/src/activity_lists.rs @@ -26,7 +26,7 @@ use crate::{ }; use activitypub_federation::{config::Data, traits::ActivityHandler}; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use url::Url; @@ -101,7 +101,7 @@ pub enum AnnouncableActivities { #[async_trait::async_trait] impl InCommunity for AnnouncableActivities { #[tracing::instrument(skip(self, context))] - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { use AnnouncableActivities::*; match self { CreateOrUpdateComment(a) => a.community(context).await, diff --git a/crates/apub/src/api/list_comments.rs b/crates/apub/src/api/list_comments.rs index c83756f54..a231b9080 100644 --- a/crates/apub/src/api/list_comments.rs +++ b/crates/apub/src/api/list_comments.rs @@ -15,14 +15,14 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn list_comments( data: Query, context: Data, local_user_view: Option, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; check_private_instance(&local_user_view, &local_site)?; diff --git a/crates/apub/src/api/list_posts.rs b/crates/apub/src/api/list_posts.rs index 384f1b60e..87e4bc679 100644 --- a/crates/apub/src/api/list_posts.rs +++ b/crates/apub/src/api/list_posts.rs @@ -15,14 +15,14 @@ use lemmy_db_views::{ post_view::PostQuery, structs::{LocalUserView, PaginationCursor, SiteView}, }; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn list_posts( data: Query, context: Data, local_user_view: Option, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = SiteView::read_local(&mut context.pool()).await?; check_private_instance(&local_user_view, &local_site.local_site)?; diff --git a/crates/apub/src/api/read_community.rs b/crates/apub/src/api/read_community.rs index a41deb32c..0d32a0b49 100644 --- a/crates/apub/src/api/read_community.rs +++ b/crates/apub/src/api/read_community.rs @@ -13,14 +13,14 @@ use lemmy_db_schema::source::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorExt2, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorExt2, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn get_community( data: Query, context: Data, local_user_view: Option, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; if data.name.is_none() && data.id.is_none() { diff --git a/crates/apub/src/api/read_person.rs b/crates/apub/src/api/read_person.rs index c779657c8..d4015f62d 100644 --- a/crates/apub/src/api/read_person.rs +++ b/crates/apub/src/api/read_person.rs @@ -13,14 +13,14 @@ use lemmy_db_views::{ structs::{LocalUserView, SiteView}, }; use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt2, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt2, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn read_person( data: Query, context: Data, local_user_view: Option, -) -> Result, LemmyError> { +) -> LemmyResult> { // Check to make sure a person name or an id is given if data.username.is_none() && data.person_id.is_none() { Err(LemmyErrorType::NoIdGiven)? diff --git a/crates/apub/src/api/resolve_object.rs b/crates/apub/src/api/resolve_object.rs index 6d672a8cd..6ab98a052 100644 --- a/crates/apub/src/api/resolve_object.rs +++ b/crates/apub/src/api/resolve_object.rs @@ -13,14 +13,14 @@ use lemmy_api_common::{ use lemmy_db_schema::{newtypes::PersonId, source::local_site::LocalSite, utils::DbPool}; use lemmy_db_views::structs::{CommentView, LocalUserView, PostView}; use lemmy_db_views_actor::structs::{CommunityView, PersonView}; -use lemmy_utils::error::{LemmyError, LemmyErrorExt2, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorExt2, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn resolve_object( data: Query, context: Data, local_user_view: Option, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = LocalSite::read(&mut context.pool()).await?; check_private_instance(&local_user_view, &local_site)?; let person_id = local_user_view.map(|v| v.person.id); @@ -46,7 +46,7 @@ async fn convert_response( object: SearchableObjects, user_id: Option, pool: &mut DbPool<'_>, -) -> Result, LemmyError> { +) -> LemmyResult> { use SearchableObjects::*; let removed_or_deleted; let mut res = ResolveObjectResponse::default(); diff --git a/crates/apub/src/api/search.rs b/crates/apub/src/api/search.rs index 32128a3c1..0cac8351a 100644 --- a/crates/apub/src/api/search.rs +++ b/crates/apub/src/api/search.rs @@ -13,14 +13,14 @@ use lemmy_db_views::{ structs::{LocalUserView, SiteView}, }; use lemmy_db_views_actor::{community_view::CommunityQuery, person_view::PersonQuery}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn search( data: Query, context: Data, local_user_view: Option, -) -> Result, LemmyError> { +) -> LemmyResult> { let local_site = SiteView::read_local(&mut context.pool()).await?; check_private_instance(&local_user_view, &local_site.local_site)?; diff --git a/crates/apub/src/api/user_settings_backup.rs b/crates/apub/src/api/user_settings_backup.rs index 4c1edcbff..8053d66a0 100644 --- a/crates/apub/src/api/user_settings_backup.rs +++ b/crates/apub/src/api/user_settings_backup.rs @@ -26,7 +26,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::{ - error::{LemmyError, LemmyErrorType, LemmyResult, MAX_API_PARAM_ELEMENTS}, + error::{LemmyErrorType, LemmyResult, MAX_API_PARAM_ELEMENTS}, spawn_try_task, }; use serde::{Deserialize, Serialize}; @@ -70,7 +70,7 @@ pub struct UserSettingsBackup { pub async fn export_settings( local_user_view: LocalUserView, context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { let lists = LocalUser::export_backup(&mut context.pool(), local_user_view.person.id).await?; let vec_into = |vec: Vec<_>| vec.into_iter().map(Into::into).collect(); @@ -97,7 +97,7 @@ pub async fn import_settings( data: Json, local_user_view: LocalUserView, context: Data, -) -> Result, LemmyError> { +) -> LemmyResult> { let person_form = PersonUpdateForm { display_name: Some(data.display_name.clone()), bio: Some(data.bio.clone()), diff --git a/crates/apub/src/collections/community_moderators.rs b/crates/apub/src/collections/community_moderators.rs index 0532d0aef..02b912f44 100644 --- a/crates/apub/src/collections/community_moderators.rs +++ b/crates/apub/src/collections/community_moderators.rs @@ -15,7 +15,7 @@ use lemmy_db_schema::{ traits::Joinable, }; use lemmy_db_views_actor::structs::CommunityModeratorView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; #[derive(Clone, Debug)] @@ -29,10 +29,7 @@ impl Collection for ApubCommunityModerators { type Error = LemmyError; #[tracing::instrument(skip_all)] - async fn read_local( - owner: &Self::Owner, - data: &Data, - ) -> Result { + async fn read_local(owner: &Self::Owner, data: &Data) -> LemmyResult { let moderators = CommunityModeratorView::for_community(&mut data.pool(), owner.id).await?; let ordered_items = moderators .into_iter() @@ -50,7 +47,7 @@ impl Collection for ApubCommunityModerators { group_moderators: &GroupModerators, expected_domain: &Url, _data: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { verify_domains_match(&group_moderators.id, expected_domain)?; Ok(()) } @@ -60,7 +57,7 @@ impl Collection for ApubCommunityModerators { apub: Self::Kind, owner: &Self::Owner, data: &Data, - ) -> Result { + ) -> LemmyResult { let community_id = owner.id; let current_moderators = CommunityModeratorView::for_community(&mut data.pool(), community_id).await?; @@ -118,7 +115,6 @@ mod tests { }, traits::Crud, }; - use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serial_test::serial; diff --git a/crates/apub/src/collections/community_outbox.rs b/crates/apub/src/collections/community_outbox.rs index 0799db789..f56708d09 100644 --- a/crates/apub/src/collections/community_outbox.rs +++ b/crates/apub/src/collections/community_outbox.rs @@ -23,7 +23,7 @@ use lemmy_db_schema::{ traits::Crud, utils::FETCH_LIMIT_MAX, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; #[derive(Clone, Debug)] @@ -37,10 +37,7 @@ impl Collection for ApubCommunityOutbox { type Error = LemmyError; #[tracing::instrument(skip_all)] - async fn read_local( - owner: &Self::Owner, - data: &Data, - ) -> Result { + async fn read_local(owner: &Self::Owner, data: &Data) -> LemmyResult { let post_list: Vec = Post::list_for_community(&mut data.pool(), owner.id) .await? .into_iter() @@ -71,7 +68,7 @@ impl Collection for ApubCommunityOutbox { group_outbox: &GroupOutbox, expected_domain: &Url, _data: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { verify_domains_match(expected_domain, &group_outbox.id)?; Ok(()) } @@ -81,7 +78,7 @@ impl Collection for ApubCommunityOutbox { apub: Self::Kind, _owner: &Self::Owner, data: &Data, - ) -> Result { + ) -> LemmyResult { let mut outbox_activities = apub.ordered_items; if outbox_activities.len() as i64 > FETCH_LIMIT_MAX { outbox_activities = outbox_activities diff --git a/crates/apub/src/fetcher/mod.rs b/crates/apub/src/fetcher/mod.rs index 4e30b4b16..928656924 100644 --- a/crates/apub/src/fetcher/mod.rs +++ b/crates/apub/src/fetcher/mod.rs @@ -8,7 +8,7 @@ use itertools::Itertools; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::traits::ApubActor; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; pub mod post_or_comment; pub mod search; @@ -25,7 +25,7 @@ pub async fn resolve_actor_identifier( context: &Data, local_user_view: &Option, include_deleted: bool, -) -> Result +) -> LemmyResult where ActorType: Object + Object diff --git a/crates/apub/src/fetcher/post_or_comment.rs b/crates/apub/src/fetcher/post_or_comment.rs index 31c53864a..9df0a04fb 100644 --- a/crates/apub/src/fetcher/post_or_comment.rs +++ b/crates/apub/src/fetcher/post_or_comment.rs @@ -12,7 +12,7 @@ use lemmy_db_schema::{ source::{community::Community, post::Post}, traits::Crud, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use serde::Deserialize; use url::Url; @@ -40,10 +40,7 @@ impl Object for PostOrComment { } #[tracing::instrument(skip_all)] - async fn read_from_id( - object_id: Url, - data: &Data, - ) -> Result, LemmyError> { + async fn read_from_id(object_id: Url, data: &Data) -> LemmyResult> { let post = ApubPost::read_from_id(object_id.clone(), data).await?; Ok(match post { Some(o) => Some(PostOrComment::Post(o)), @@ -54,14 +51,14 @@ impl Object for PostOrComment { } #[tracing::instrument(skip_all)] - async fn delete(self, data: &Data) -> Result<(), LemmyError> { + async fn delete(self, data: &Data) -> LemmyResult<()> { match self { PostOrComment::Post(p) => p.delete(data).await, PostOrComment::Comment(c) => c.delete(data).await, } } - async fn into_json(self, _data: &Data) -> Result { + async fn into_json(self, _data: &Data) -> LemmyResult { unimplemented!() } @@ -70,7 +67,7 @@ impl Object for PostOrComment { apub: &Self::Kind, expected_domain: &Url, data: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { match apub { PageOrNote::Page(a) => ApubPost::verify(a, expected_domain, data).await, PageOrNote::Note(a) => ApubComment::verify(a, expected_domain, data).await, @@ -78,7 +75,7 @@ impl Object for PostOrComment { } #[tracing::instrument(skip_all)] - async fn from_json(apub: PageOrNote, context: &Data) -> Result { + async fn from_json(apub: PageOrNote, context: &Data) -> LemmyResult { Ok(match apub { PageOrNote::Page(p) => PostOrComment::Post(ApubPost::from_json(*p, context).await?), PageOrNote::Note(n) => PostOrComment::Comment(ApubComment::from_json(n, context).await?), @@ -88,7 +85,7 @@ impl Object for PostOrComment { #[async_trait::async_trait] impl InCommunity for PostOrComment { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let cid = match self { PostOrComment::Post(p) => p.community_id, PostOrComment::Comment(c) => { diff --git a/crates/apub/src/fetcher/search.rs b/crates/apub/src/fetcher/search.rs index 74d755da0..8c533ba88 100644 --- a/crates/apub/src/fetcher/search.rs +++ b/crates/apub/src/fetcher/search.rs @@ -10,7 +10,7 @@ use activitypub_federation::{ }; use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use serde::Deserialize; use url::Url; @@ -21,7 +21,7 @@ use url::Url; pub(crate) async fn search_query_to_object_id( mut query: String, context: &Data, -) -> Result { +) -> LemmyResult { Ok(match Url::parse(&query) { Ok(url) => { // its already an url, just go with it @@ -46,7 +46,7 @@ pub(crate) async fn search_query_to_object_id( pub(crate) async fn search_query_to_object_id_local( query: &str, context: &Data, -) -> Result { +) -> LemmyResult { let url = Url::parse(query)?; ObjectId::from(url).dereference_local(context).await } @@ -90,7 +90,7 @@ impl Object for SearchableObjects { async fn read_from_id( object_id: Url, context: &Data, - ) -> Result, LemmyError> { + ) -> LemmyResult> { let uc = UserOrCommunity::read_from_id(object_id.clone(), context).await?; if let Some(uc) = uc { return Ok(Some(SearchableObjects::PersonOrCommunity(Box::new(uc)))); @@ -107,7 +107,7 @@ impl Object for SearchableObjects { } #[tracing::instrument(skip_all)] - async fn delete(self, data: &Data) -> Result<(), LemmyError> { + async fn delete(self, data: &Data) -> LemmyResult<()> { match self { SearchableObjects::Post(p) => p.delete(data).await, SearchableObjects::Comment(c) => c.delete(data).await, @@ -118,7 +118,7 @@ impl Object for SearchableObjects { } } - async fn into_json(self, _data: &Data) -> Result { + async fn into_json(self, _data: &Data) -> LemmyResult { unimplemented!() } @@ -127,7 +127,7 @@ impl Object for SearchableObjects { apub: &Self::Kind, expected_domain: &Url, data: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { match apub { SearchableKinds::Page(a) => ApubPost::verify(a, expected_domain, data).await, SearchableKinds::Note(a) => ApubComment::verify(a, expected_domain, data).await, @@ -139,7 +139,7 @@ impl Object for SearchableObjects { } #[tracing::instrument(skip_all)] - async fn from_json(apub: Self::Kind, context: &Data) -> Result { + async fn from_json(apub: Self::Kind, context: &Data) -> LemmyResult { use SearchableKinds as SAT; use SearchableObjects as SO; Ok(match apub { diff --git a/crates/apub/src/fetcher/site_or_community_or_user.rs b/crates/apub/src/fetcher/site_or_community_or_user.rs index 76ee566c9..30b5fd568 100644 --- a/crates/apub/src/fetcher/site_or_community_or_user.rs +++ b/crates/apub/src/fetcher/site_or_community_or_user.rs @@ -9,7 +9,7 @@ use activitypub_federation::{ }; use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use reqwest::Url; use serde::{Deserialize, Serialize}; @@ -44,19 +44,19 @@ impl Object for SiteOrCommunityOrUser { async fn read_from_id( _object_id: Url, _data: &Data, - ) -> Result, LemmyError> { + ) -> LemmyResult> { unimplemented!(); } #[tracing::instrument(skip_all)] - async fn delete(self, data: &Data) -> Result<(), LemmyError> { + async fn delete(self, data: &Data) -> LemmyResult<()> { match self { SiteOrCommunityOrUser::Site(p) => p.delete(data).await, SiteOrCommunityOrUser::UserOrCommunity(p) => p.delete(data).await, } } - async fn into_json(self, _data: &Data) -> Result { + async fn into_json(self, _data: &Data) -> LemmyResult { unimplemented!() } @@ -65,7 +65,7 @@ impl Object for SiteOrCommunityOrUser { apub: &Self::Kind, expected_domain: &Url, data: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { match apub { SiteOrPersonOrGroup::Instance(a) => ApubSite::verify(a, expected_domain, data).await, SiteOrPersonOrGroup::PersonOrGroup(a) => { @@ -75,7 +75,7 @@ impl Object for SiteOrCommunityOrUser { } #[tracing::instrument(skip_all)] - async fn from_json(_apub: Self::Kind, _data: &Data) -> Result { + async fn from_json(_apub: Self::Kind, _data: &Data) -> LemmyResult { unimplemented!(); } } diff --git a/crates/apub/src/fetcher/user_or_community.rs b/crates/apub/src/fetcher/user_or_community.rs index 93e955c7b..d29cbb6b0 100644 --- a/crates/apub/src/fetcher/user_or_community.rs +++ b/crates/apub/src/fetcher/user_or_community.rs @@ -10,7 +10,7 @@ use activitypub_federation::{ use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::source::activity::ActorType; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyResult}; use serde::{Deserialize, Serialize}; use url::Url; @@ -47,10 +47,7 @@ impl Object for UserOrCommunity { } #[tracing::instrument(skip_all)] - async fn read_from_id( - object_id: Url, - data: &Data, - ) -> Result, LemmyError> { + async fn read_from_id(object_id: Url, data: &Data) -> LemmyResult> { let person = ApubPerson::read_from_id(object_id.clone(), data).await?; Ok(match person { Some(o) => Some(UserOrCommunity::User(o)), @@ -61,14 +58,14 @@ impl Object for UserOrCommunity { } #[tracing::instrument(skip_all)] - async fn delete(self, data: &Data) -> Result<(), LemmyError> { + async fn delete(self, data: &Data) -> LemmyResult<()> { match self { UserOrCommunity::User(p) => p.delete(data).await, UserOrCommunity::Community(p) => p.delete(data).await, } } - async fn into_json(self, _data: &Data) -> Result { + async fn into_json(self, _data: &Data) -> LemmyResult { unimplemented!() } @@ -77,7 +74,7 @@ impl Object for UserOrCommunity { apub: &Self::Kind, expected_domain: &Url, data: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { match apub { PersonOrGroup::Person(a) => ApubPerson::verify(a, expected_domain, data).await, PersonOrGroup::Group(a) => ApubCommunity::verify(a, expected_domain, data).await, @@ -85,7 +82,7 @@ impl Object for UserOrCommunity { } #[tracing::instrument(skip_all)] - async fn from_json(apub: Self::Kind, data: &Data) -> Result { + async fn from_json(apub: Self::Kind, data: &Data) -> LemmyResult { Ok(match apub { PersonOrGroup::Person(p) => UserOrCommunity::User(ApubPerson::from_json(p, data).await?), PersonOrGroup::Group(p) => { diff --git a/crates/apub/src/http/comment.rs b/crates/apub/src/http/comment.rs index 200dda8ed..d6b3c818d 100644 --- a/crates/apub/src/http/comment.rs +++ b/crates/apub/src/http/comment.rs @@ -15,7 +15,7 @@ use lemmy_db_schema::{ source::{comment::Comment, community::Community, post::Post}, traits::Crud, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::Deserialize; #[derive(Deserialize)] @@ -28,7 +28,7 @@ pub(crate) struct CommentQuery { pub(crate) async fn get_apub_comment( info: Path, context: Data, -) -> Result { +) -> LemmyResult { let id = CommentId(info.comment_id.parse::()?); // Can't use CommentView here because it excludes deleted/removed/local-only items let comment: ApubComment = Comment::read(&mut context.pool(), id).await?.into(); diff --git a/crates/apub/src/http/community.rs b/crates/apub/src/http/community.rs index cf0d1625d..2085ed1ac 100644 --- a/crates/apub/src/http/community.rs +++ b/crates/apub/src/http/community.rs @@ -18,7 +18,7 @@ use activitypub_federation::{ use actix_web::{web, web::Bytes, HttpRequest, HttpResponse}; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{source::community::Community, traits::ApubActor}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::Deserialize; #[derive(Deserialize, Clone)] @@ -31,7 +31,7 @@ pub(crate) struct CommunityQuery { pub(crate) async fn get_apub_community_http( info: web::Path, context: Data, -) -> Result { +) -> LemmyResult { let community: ApubCommunity = Community::read_from_name(&mut context.pool(), &info.community_name, true) .await? @@ -52,7 +52,7 @@ pub async fn community_inbox( request: HttpRequest, body: Bytes, data: Data, -) -> Result { +) -> LemmyResult { receive_activity::, ApubPerson, LemmyContext>( request, body, &data, ) @@ -63,7 +63,7 @@ pub async fn community_inbox( pub(crate) async fn get_apub_community_followers( info: web::Path, context: Data, -) -> Result { +) -> LemmyResult { let community = Community::read_from_name(&mut context.pool(), &info.community_name, false).await?; check_community_public(&community)?; @@ -76,7 +76,7 @@ pub(crate) async fn get_apub_community_followers( pub(crate) async fn get_apub_community_outbox( info: web::Path, context: Data, -) -> Result { +) -> LemmyResult { let community: ApubCommunity = Community::read_from_name(&mut context.pool(), &info.community_name, false) .await? @@ -90,7 +90,7 @@ pub(crate) async fn get_apub_community_outbox( pub(crate) async fn get_apub_community_moderators( info: web::Path, context: Data, -) -> Result { +) -> LemmyResult { let community: ApubCommunity = Community::read_from_name(&mut context.pool(), &info.community_name, false) .await? @@ -104,7 +104,7 @@ pub(crate) async fn get_apub_community_moderators( pub(crate) async fn get_apub_community_featured( info: web::Path, context: Data, -) -> Result { +) -> LemmyResult { let community: ApubCommunity = Community::read_from_name(&mut context.pool(), &info.community_name, false) .await? @@ -127,7 +127,6 @@ pub(crate) mod tests { traits::Crud, CommunityVisibility, }; - use lemmy_utils::error::LemmyResult; use serde::de::DeserializeOwned; use serial_test::serial; @@ -135,7 +134,7 @@ pub(crate) mod tests { deleted: bool, visibility: CommunityVisibility, context: &Data, - ) -> Result<(Instance, Community), LemmyError> { + ) -> LemmyResult<(Instance, Community)> { let instance = Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?; let community_form = CommunityInsertForm::builder() @@ -150,7 +149,7 @@ pub(crate) mod tests { Ok((instance, community)) } - async fn decode_response(res: HttpResponse) -> Result { + async fn decode_response(res: HttpResponse) -> LemmyResult { let body = to_bytes(res.into_body()).await.unwrap(); let body = std::str::from_utf8(&body)?; Ok(serde_json::from_str(body)?) diff --git a/crates/apub/src/http/mod.rs b/crates/apub/src/http/mod.rs index b400e3dab..86c51338a 100644 --- a/crates/apub/src/http/mod.rs +++ b/crates/apub/src/http/mod.rs @@ -18,7 +18,7 @@ use lemmy_db_schema::{ source::{activity::SentActivity, community::Community}, CommunityVisibility, }; -use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult}; +use lemmy_utils::error::{LemmyErrorType, LemmyResult}; use serde::{Deserialize, Serialize}; use std::ops::Deref; use url::Url; @@ -88,7 +88,7 @@ pub struct ActivityQuery { pub(crate) async fn get_activity( info: web::Path, context: web::Data, -) -> Result { +) -> LemmyResult { let settings = context.settings(); let activity_id = Url::parse(&format!( "{}/activities/{}/{}", diff --git a/crates/apub/src/http/person.rs b/crates/apub/src/http/person.rs index 254313634..b34f166b0 100644 --- a/crates/apub/src/http/person.rs +++ b/crates/apub/src/http/person.rs @@ -14,7 +14,7 @@ use activitypub_federation::{ use actix_web::{web, web::Bytes, HttpRequest, HttpResponse}; use lemmy_api_common::{context::LemmyContext, utils::generate_outbox_url}; use lemmy_db_schema::{source::person::Person, traits::ApubActor}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::Deserialize; #[derive(Deserialize)] @@ -27,7 +27,7 @@ pub struct PersonQuery { pub(crate) async fn get_apub_person_http( info: web::Path, context: Data, -) -> Result { +) -> LemmyResult { let user_name = info.into_inner().user_name; // TODO: this needs to be able to read deleted persons, so that it can send tombstones let person: ApubPerson = Person::read_from_name(&mut context.pool(), &user_name, true) @@ -48,7 +48,7 @@ pub async fn person_inbox( request: HttpRequest, body: Bytes, data: Data, -) -> Result { +) -> LemmyResult { receive_activity::, UserOrCommunity, LemmyContext>( request, body, &data, ) @@ -59,7 +59,7 @@ pub async fn person_inbox( pub(crate) async fn get_apub_person_outbox( info: web::Path, context: Data, -) -> Result { +) -> LemmyResult { let person = Person::read_from_name(&mut context.pool(), &info.user_name, false).await?; let outbox_id = generate_outbox_url(&person.actor_id)?.into(); let outbox = EmptyOutbox::new(outbox_id)?; diff --git a/crates/apub/src/http/post.rs b/crates/apub/src/http/post.rs index 6ca07f684..ce6612826 100644 --- a/crates/apub/src/http/post.rs +++ b/crates/apub/src/http/post.rs @@ -15,7 +15,7 @@ use lemmy_db_schema::{ source::{community::Community, post::Post}, traits::Crud, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::Deserialize; #[derive(Deserialize)] @@ -28,7 +28,7 @@ pub(crate) struct PostQuery { pub(crate) async fn get_apub_post( info: web::Path, context: Data, -) -> Result { +) -> LemmyResult { let id = PostId(info.post_id.parse::()?); // Can't use PostView here because it excludes deleted/removed/local-only items let post: ApubPost = Post::read(&mut context.pool(), id).await?.into(); diff --git a/crates/apub/src/http/site.rs b/crates/apub/src/http/site.rs index 410b29b18..622c0f676 100644 --- a/crates/apub/src/http/site.rs +++ b/crates/apub/src/http/site.rs @@ -7,12 +7,10 @@ use activitypub_federation::{config::Data, traits::Object}; use actix_web::HttpResponse; use lemmy_api_common::context::LemmyContext; use lemmy_db_views::structs::SiteView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use url::Url; -pub(crate) async fn get_apub_site_http( - context: Data, -) -> Result { +pub(crate) async fn get_apub_site_http(context: Data) -> LemmyResult { let site: ApubSite = SiteView::read_local(&mut context.pool()).await?.site.into(); let apub = site.into_json(&context).await?; @@ -20,9 +18,7 @@ pub(crate) async fn get_apub_site_http( } #[tracing::instrument(skip_all)] -pub(crate) async fn get_apub_site_outbox( - context: Data, -) -> Result { +pub(crate) async fn get_apub_site_outbox(context: Data) -> LemmyResult { let outbox_id = format!( "{}/site_outbox", context.settings().get_protocol_and_hostname() diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index 5d10dd93d..29c9a12eb 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -77,7 +77,7 @@ impl UrlVerifier for VerifyUrlData { /// - URL being in the allowlist (if it is active) /// - URL not being in the blocklist (if it is active) #[tracing::instrument(skip(local_site_data))] -fn check_apub_id_valid(apub_id: &Url, local_site_data: &LocalSiteData) -> Result<(), LemmyError> { +fn check_apub_id_valid(apub_id: &Url, local_site_data: &LocalSiteData) -> LemmyResult<()> { let domain = apub_id.domain().expect("apud id has domain").to_string(); if !local_site_data @@ -157,7 +157,7 @@ pub(crate) async fn check_apub_id_valid_with_strictness( apub_id: &Url, is_strict: bool, context: &LemmyContext, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let domain = apub_id.domain().expect("apud id has domain").to_string(); let local_instance = context .settings() @@ -198,10 +198,7 @@ pub(crate) async fn check_apub_id_valid_with_strictness( /// This ensures that the same activity doesnt get received and processed more than once, which /// would be a waste of resources. #[tracing::instrument(skip(data))] -async fn insert_received_activity( - ap_id: &Url, - data: &Data, -) -> Result<(), LemmyError> { +async fn insert_received_activity(ap_id: &Url, data: &Data) -> LemmyResult<()> { ReceivedActivity::create(&mut data.pool(), &ap_id.clone().into()).await?; Ok(()) } diff --git a/crates/apub/src/mentions.rs b/crates/apub/src/mentions.rs index b088dfd03..92b07db8e 100644 --- a/crates/apub/src/mentions.rs +++ b/crates/apub/src/mentions.rs @@ -11,7 +11,7 @@ use lemmy_db_schema::{ traits::Crud, utils::DbPool, }; -use lemmy_utils::{error::LemmyError, utils::mention::scrape_text_for_mentions}; +use lemmy_utils::{error::LemmyResult, utils::mention::scrape_text_for_mentions}; use serde::{Deserialize, Serialize}; use serde_json::Value; use url::Url; @@ -44,7 +44,7 @@ pub async fn collect_non_local_mentions( comment: &ApubComment, community_id: ObjectId, context: &Data, -) -> Result { +) -> LemmyResult { let parent_creator = get_comment_parent_creator(&mut context.pool(), comment).await?; let mut addressed_ccs: Vec = vec![community_id.into(), parent_creator.id()]; @@ -94,7 +94,7 @@ pub async fn collect_non_local_mentions( async fn get_comment_parent_creator( pool: &mut DbPool<'_>, comment: &Comment, -) -> Result { +) -> LemmyResult { let parent_creator_id = if let Some(parent_comment_id) = comment.parent_comment_id() { let parent_comment = Comment::read(pool, parent_comment_id).await?; parent_comment.creator_id diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index 1acef5cbf..e3128e439 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -32,7 +32,7 @@ use lemmy_db_schema::{ utils::naive_now, }; use lemmy_utils::{ - error::{LemmyError, LemmyErrorType}, + error::{LemmyError, LemmyErrorType, LemmyResult}, utils::markdown::markdown_to_html, }; use std::ops::Deref; @@ -68,7 +68,7 @@ impl Object for ApubComment { async fn read_from_id( object_id: Url, context: &Data, - ) -> Result, LemmyError> { + ) -> LemmyResult> { Ok( Comment::read_from_apub_id(&mut context.pool(), object_id) .await? @@ -77,7 +77,7 @@ impl Object for ApubComment { } #[tracing::instrument(skip_all)] - async fn delete(self, context: &Data) -> Result<(), LemmyError> { + async fn delete(self, context: &Data) -> LemmyResult<()> { if !self.deleted { let form = CommentUpdateForm { deleted: Some(true), @@ -89,7 +89,7 @@ impl Object for ApubComment { } #[tracing::instrument(skip_all)] - async fn into_json(self, context: &Data) -> Result { + async fn into_json(self, context: &Data) -> LemmyResult { let creator_id = self.creator_id; let creator = Person::read(&mut context.pool(), creator_id).await?; @@ -133,7 +133,7 @@ impl Object for ApubComment { note: &Note, expected_domain: &Url, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { verify_domains_match(note.id.inner(), expected_domain)?; verify_domains_match(note.attributed_to.inner(), note.id.inner())?; verify_is_public(¬e.to, ¬e.cc)?; @@ -159,7 +159,7 @@ impl Object for ApubComment { /// /// If the parent community, post and comment(s) are not known locally, these are also fetched. #[tracing::instrument(skip_all)] - async fn from_json(note: Note, context: &Data) -> Result { + async fn from_json(note: Note, context: &Data) -> LemmyResult { let creator = note.attributed_to.dereference(context).await?; let (post, parent_comment) = note.get_parents(context).await?; @@ -213,7 +213,6 @@ pub(crate) mod tests { use assert_json_diff::assert_json_include; use html2md::parse_html; use lemmy_db_schema::source::site::Site; - use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serial_test::serial; diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 83cdc3a49..6638cc68d 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -38,7 +38,11 @@ use lemmy_db_schema::{ utils::naive_now, }; use lemmy_db_views_actor::structs::CommunityFollowerView; -use lemmy_utils::{error::LemmyError, spawn_try_task, utils::markdown::markdown_to_html}; +use lemmy_utils::{ + error::{LemmyError, LemmyResult}, + spawn_try_task, + utils::markdown::markdown_to_html, +}; use std::ops::Deref; use url::Url; @@ -72,7 +76,7 @@ impl Object for ApubCommunity { async fn read_from_id( object_id: Url, context: &Data, - ) -> Result, LemmyError> { + ) -> LemmyResult> { Ok( Community::read_from_apub_id(&mut context.pool(), &object_id.into()) .await? @@ -81,7 +85,7 @@ impl Object for ApubCommunity { } #[tracing::instrument(skip_all)] - async fn delete(self, context: &Data) -> Result<(), LemmyError> { + async fn delete(self, context: &Data) -> LemmyResult<()> { let form = CommunityUpdateForm { deleted: Some(true), ..Default::default() @@ -91,7 +95,7 @@ impl Object for ApubCommunity { } #[tracing::instrument(skip_all)] - async fn into_json(self, data: &Data) -> Result { + async fn into_json(self, data: &Data) -> LemmyResult { let community_id = self.id; let langs = CommunityLanguage::read(&mut data.pool(), community_id).await?; let language = LanguageTag::new_multiple(langs, &mut data.pool()).await?; @@ -128,16 +132,13 @@ impl Object for ApubCommunity { group: &Group, expected_domain: &Url, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { group.verify(expected_domain, context).await } /// Converts a `Group` to `Community`, inserts it into the database and updates moderators. #[tracing::instrument(skip_all)] - async fn from_json( - group: Group, - context: &Data, - ) -> Result { + async fn from_json(group: Group, context: &Data) -> LemmyResult { let instance_id = fetch_instance_actor_for_object(&group.id, context).await?; let local_site = LocalSite::read(&mut context.pool()).await.ok(); @@ -235,10 +236,7 @@ impl GetActorType for ApubCommunity { impl ApubCommunity { /// For a given community, returns the inboxes of all followers. #[tracing::instrument(skip_all)] - pub(crate) async fn get_follower_inboxes( - &self, - context: &LemmyContext, - ) -> Result, LemmyError> { + pub(crate) async fn get_follower_inboxes(&self, context: &LemmyContext) -> LemmyResult> { let id = self.id; let local_site_data = local_site_data_cached(&mut context.pool()).await?; @@ -265,7 +263,6 @@ pub(crate) mod tests { }; use activitypub_federation::fetch::collection_id::CollectionId; use lemmy_db_schema::source::site::Site; - use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serial_test::serial; diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 6894643d6..021d2b1cd 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -39,7 +39,7 @@ use lemmy_db_schema::{ utils::naive_now, }; use lemmy_utils::{ - error::LemmyError, + error::{LemmyError, LemmyResult}, utils::{ markdown::markdown_to_html, slurs::{check_slurs, check_slurs_opt}, @@ -76,10 +76,7 @@ impl Object for ApubSite { } #[tracing::instrument(skip_all)] - async fn read_from_id( - object_id: Url, - data: &Data, - ) -> Result, LemmyError> { + async fn read_from_id(object_id: Url, data: &Data) -> LemmyResult> { Ok( Site::read_from_apub_id(&mut data.pool(), &object_id.into()) .await? @@ -87,12 +84,12 @@ impl Object for ApubSite { ) } - async fn delete(self, _data: &Data) -> Result<(), LemmyError> { + async fn delete(self, _data: &Data) -> LemmyResult<()> { unimplemented!() } #[tracing::instrument(skip_all)] - async fn into_json(self, data: &Data) -> Result { + async fn into_json(self, data: &Data) -> LemmyResult { let site_id = self.id; let langs = SiteLanguage::read(&mut data.pool(), site_id).await?; let language = LanguageTag::new_multiple(langs, &mut data.pool()).await?; @@ -124,7 +121,7 @@ impl Object for ApubSite { apub: &Self::Kind, expected_domain: &Url, data: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { check_apub_id_valid_with_strictness(apub.id.inner(), true, data).await?; verify_domains_match(expected_domain, apub.id.inner())?; @@ -137,7 +134,7 @@ impl Object for ApubSite { } #[tracing::instrument(skip_all)] - async fn from_json(apub: Self::Kind, context: &Data) -> Result { + async fn from_json(apub: Self::Kind, context: &Data) -> LemmyResult { let domain = apub.id.inner().domain().expect("group id has domain"); let instance = DbInstance::read_or_create(&mut context.pool(), domain.to_string()).await?; @@ -200,7 +197,7 @@ impl GetActorType for ApubSite { pub(in crate::objects) async fn fetch_instance_actor_for_object + Clone>( object_id: &T, context: &Data, -) -> Result { +) -> LemmyResult { let object_id: Url = object_id.clone().into(); let instance_id = Site::instance_actor_id_from_url(object_id); let site = ObjectId::::from(instance_id.clone()) @@ -225,7 +222,6 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object + C pub(crate) mod tests { use super::*; use crate::protocol::tests::file_to_json_object; - use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serial_test::serial; diff --git a/crates/apub/src/objects/mod.rs b/crates/apub/src/objects/mod.rs index cabd07e6d..693521ee1 100644 --- a/crates/apub/src/objects/mod.rs +++ b/crates/apub/src/objects/mod.rs @@ -2,7 +2,7 @@ use crate::protocol::Source; use activitypub_federation::protocol::values::MediaTypeMarkdownOrHtml; use anyhow::anyhow; use html2md::parse_html; -use lemmy_utils::{error::LemmyError, settings::structs::Settings}; +use lemmy_utils::{error::LemmyResult, settings::structs::Settings}; use url::Url; pub mod comment; @@ -43,7 +43,7 @@ pub(crate) fn read_from_string_or_source_opt( /// wrapped in Announce. If we simply receive this like any other federated object, overwrite the /// existing, local Post. In particular, it will set the field local = false, so that the object /// can't be fetched from the Activitypub HTTP endpoint anymore (which only serves local objects). -pub(crate) fn verify_is_remote_object(id: &Url, settings: &Settings) -> Result<(), LemmyError> { +pub(crate) fn verify_is_remote_object(id: &Url, settings: &Settings) -> LemmyResult<()> { let local_domain = settings.get_hostname_without_port()?; if id.domain() == Some(&local_domain) { Err(anyhow!("cant accept local object from remote instance").into()) diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index d4456344f..c99e09f72 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -38,7 +38,7 @@ use lemmy_db_schema::{ utils::naive_now, }; use lemmy_utils::{ - error::LemmyError, + error::{LemmyError, LemmyResult}, utils::{ markdown::markdown_to_html, slurs::{check_slurs, check_slurs_opt}, @@ -77,7 +77,7 @@ impl Object for ApubPerson { async fn read_from_id( object_id: Url, context: &Data, - ) -> Result, LemmyError> { + ) -> LemmyResult> { Ok( DbPerson::read_from_apub_id(&mut context.pool(), &object_id.into()) .await? @@ -86,7 +86,7 @@ impl Object for ApubPerson { } #[tracing::instrument(skip_all)] - async fn delete(self, context: &Data) -> Result<(), LemmyError> { + async fn delete(self, context: &Data) -> LemmyResult<()> { let form = PersonUpdateForm { deleted: Some(true), ..Default::default() @@ -96,7 +96,7 @@ impl Object for ApubPerson { } #[tracing::instrument(skip_all)] - async fn into_json(self, _context: &Data) -> Result { + async fn into_json(self, _context: &Data) -> LemmyResult { let kind = if self.bot_account { UserTypes::Service } else { @@ -130,7 +130,7 @@ impl Object for ApubPerson { person: &Person, expected_domain: &Url, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { let local_site_data = local_site_data_cached(&mut context.pool()).await?; let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site); check_slurs(&person.preferred_username, slur_regex)?; @@ -145,10 +145,7 @@ impl Object for ApubPerson { } #[tracing::instrument(skip_all)] - async fn from_json( - person: Person, - context: &Data, - ) -> Result { + async fn from_json(person: Person, context: &Data) -> LemmyResult { let instance_id = fetch_instance_actor_for_object(&person.id, context).await?; let local_site = LocalSite::read(&mut context.pool()).await.ok(); @@ -228,7 +225,6 @@ pub(crate) mod tests { }; use activitypub_federation::fetch::object_id::ObjectId; use lemmy_db_schema::source::site::Site; - use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serial_test::serial; diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index a53acee28..ba1e3f6a1 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -45,7 +45,7 @@ use lemmy_db_schema::{ }; use lemmy_db_views_actor::structs::CommunityModeratorView; use lemmy_utils::{ - error::LemmyError, + error::{LemmyError, LemmyResult}, utils::{markdown::markdown_to_html, slurs::check_slurs_opt, validation::check_url_scheme}, }; use std::ops::Deref; @@ -84,7 +84,7 @@ impl Object for ApubPost { async fn read_from_id( object_id: Url, context: &Data, - ) -> Result, LemmyError> { + ) -> LemmyResult> { Ok( Post::read_from_apub_id(&mut context.pool(), object_id) .await? @@ -93,7 +93,7 @@ impl Object for ApubPost { } #[tracing::instrument(skip_all)] - async fn delete(self, context: &Data) -> Result<(), LemmyError> { + async fn delete(self, context: &Data) -> LemmyResult<()> { if !self.deleted { let form = PostUpdateForm { deleted: Some(true), @@ -106,7 +106,7 @@ impl Object for ApubPost { // Turn a Lemmy post into an ActivityPub page that can be sent out over the network. #[tracing::instrument(skip_all)] - async fn into_json(self, context: &Data) -> Result { + async fn into_json(self, context: &Data) -> LemmyResult { let creator_id = self.creator_id; let creator = Person::read(&mut context.pool(), creator_id).await?; let community_id = self.community_id; @@ -160,7 +160,7 @@ impl Object for ApubPost { page: &Page, expected_domain: &Url, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { // We can't verify the domain in case of mod action, because the mod may be on a different // instance from the post author. if !page.is_mod_action(context).await? { @@ -182,7 +182,7 @@ impl Object for ApubPost { } #[tracing::instrument(skip_all)] - async fn from_json(page: Page, context: &Data) -> Result { + async fn from_json(page: Page, context: &Data) -> LemmyResult { let creator = page.creator()?.dereference(context).await?; let community = page.community(context).await?; if community.posting_restricted_to_mods { @@ -307,7 +307,6 @@ mod tests { protocol::tests::file_to_json_object, }; use lemmy_db_schema::source::site::Site; - use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serial_test::serial; diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index c32aa6458..a78324633 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -26,7 +26,7 @@ use lemmy_db_schema::{ utils::naive_now, }; use lemmy_utils::{ - error::{LemmyError, LemmyErrorType}, + error::{LemmyError, LemmyErrorType, LemmyResult}, utils::markdown::markdown_to_html, }; use std::ops::Deref; @@ -62,7 +62,7 @@ impl Object for ApubPrivateMessage { async fn read_from_id( object_id: Url, context: &Data, - ) -> Result, LemmyError> { + ) -> LemmyResult> { Ok( PrivateMessage::read_from_apub_id(&mut context.pool(), object_id) .await? @@ -70,13 +70,13 @@ impl Object for ApubPrivateMessage { ) } - async fn delete(self, _context: &Data) -> Result<(), LemmyError> { + async fn delete(self, _context: &Data) -> LemmyResult<()> { // do nothing, because pm can't be fetched over http unimplemented!() } #[tracing::instrument(skip_all)] - async fn into_json(self, context: &Data) -> Result { + async fn into_json(self, context: &Data) -> LemmyResult { let creator_id = self.creator_id; let creator = Person::read(&mut context.pool(), creator_id).await?; @@ -102,7 +102,7 @@ impl Object for ApubPrivateMessage { note: &ChatMessage, expected_domain: &Url, context: &Data, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { verify_domains_match(note.id.inner(), expected_domain)?; verify_domains_match(note.attributed_to.inner(), note.id.inner())?; @@ -121,7 +121,7 @@ impl Object for ApubPrivateMessage { async fn from_json( note: ChatMessage, context: &Data, - ) -> Result { + ) -> LemmyResult { let creator = note.attributed_to.dereference(context).await?; let recipient = note.to[0].dereference(context).await?; check_person_block(creator.id, recipient.id, &mut context.pool()).await?; @@ -161,7 +161,6 @@ mod tests { }; use assert_json_diff::assert_json_include; use lemmy_db_schema::source::site::Site; - use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serial_test::serial; diff --git a/crates/apub/src/protocol/activities/block/block_user.rs b/crates/apub/src/protocol/activities/block/block_user.rs index c5cb4306c..c1a4c64c7 100644 --- a/crates/apub/src/protocol/activities/block/block_user.rs +++ b/crates/apub/src/protocol/activities/block/block_user.rs @@ -12,7 +12,7 @@ use activitypub_federation::{ use anyhow::anyhow; use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use url::Url; @@ -45,7 +45,7 @@ pub struct BlockUser { #[async_trait::async_trait] impl InCommunity for BlockUser { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let target = self.target.dereference(context).await?; let community = match target { SiteOrCommunity::Community(c) => c, diff --git a/crates/apub/src/protocol/activities/block/undo_block_user.rs b/crates/apub/src/protocol/activities/block/undo_block_user.rs index 758d3fd4b..491ec7ed1 100644 --- a/crates/apub/src/protocol/activities/block/undo_block_user.rs +++ b/crates/apub/src/protocol/activities/block/undo_block_user.rs @@ -10,7 +10,7 @@ use activitypub_federation::{ protocol::helpers::deserialize_one_or_many, }; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use url::Url; @@ -33,7 +33,7 @@ pub struct UndoBlockUser { #[async_trait::async_trait] impl InCommunity for UndoBlockUser { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let community = self.object.community(context).await?; if let Some(audience) = &self.audience { verify_community_matches(audience, community.actor_id.clone())?; diff --git a/crates/apub/src/protocol/activities/community/collection_add.rs b/crates/apub/src/protocol/activities/community/collection_add.rs index edf67740a..777ad8b62 100644 --- a/crates/apub/src/protocol/activities/community/collection_add.rs +++ b/crates/apub/src/protocol/activities/community/collection_add.rs @@ -11,7 +11,7 @@ use activitypub_federation::{ }; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::source::community::Community; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use url::Url; @@ -33,7 +33,7 @@ pub struct CollectionAdd { #[async_trait::async_trait] impl InCommunity for CollectionAdd { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let (community, _) = Community::get_by_collection_url(&mut context.pool(), &self.clone().target.into()).await?; if let Some(audience) = &self.audience { diff --git a/crates/apub/src/protocol/activities/community/collection_remove.rs b/crates/apub/src/protocol/activities/community/collection_remove.rs index 960951732..afc0c24a0 100644 --- a/crates/apub/src/protocol/activities/community/collection_remove.rs +++ b/crates/apub/src/protocol/activities/community/collection_remove.rs @@ -11,7 +11,7 @@ use activitypub_federation::{ }; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::source::community::Community; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use url::Url; @@ -33,7 +33,7 @@ pub struct CollectionRemove { #[async_trait::async_trait] impl InCommunity for CollectionRemove { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let (community, _) = Community::get_by_collection_url(&mut context.pool(), &self.clone().target.into()).await?; if let Some(audience) = &self.audience { diff --git a/crates/apub/src/protocol/activities/community/lock_page.rs b/crates/apub/src/protocol/activities/community/lock_page.rs index 33b108531..0a4a2ff75 100644 --- a/crates/apub/src/protocol/activities/community/lock_page.rs +++ b/crates/apub/src/protocol/activities/community/lock_page.rs @@ -11,7 +11,7 @@ use activitypub_federation::{ }; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{source::community::Community, traits::Crud}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use strum_macros::Display; use url::Url; @@ -53,7 +53,7 @@ pub struct UndoLockPage { #[async_trait::async_trait] impl InCommunity for LockPage { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let post = self.object.dereference(context).await?; let community = Community::read(&mut context.pool(), post.community_id).await?; if let Some(audience) = &self.audience { @@ -65,7 +65,7 @@ impl InCommunity for LockPage { #[async_trait::async_trait] impl InCommunity for UndoLockPage { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let community = self.object.community(context).await?; if let Some(audience) = &self.audience { verify_community_matches(audience, community.actor_id.clone())?; diff --git a/crates/apub/src/protocol/activities/community/report.rs b/crates/apub/src/protocol/activities/community/report.rs index adcddfdfc..7698cde50 100644 --- a/crates/apub/src/protocol/activities/community/report.rs +++ b/crates/apub/src/protocol/activities/community/report.rs @@ -11,7 +11,7 @@ use activitypub_federation::{ protocol::helpers::deserialize_one, }; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult}; +use lemmy_utils::error::{LemmyErrorType, LemmyResult}; use serde::{Deserialize, Serialize}; use url::Url; @@ -71,7 +71,7 @@ impl ReportObject { #[async_trait::async_trait] impl InCommunity for Report { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let community = self.to[0].dereference(context).await?; if let Some(audience) = &self.audience { verify_community_matches(audience, community.actor_id.clone())?; diff --git a/crates/apub/src/protocol/activities/community/update.rs b/crates/apub/src/protocol/activities/community/update.rs index 49ec1f5d6..268f05073 100644 --- a/crates/apub/src/protocol/activities/community/update.rs +++ b/crates/apub/src/protocol/activities/community/update.rs @@ -10,7 +10,7 @@ use activitypub_federation::{ protocol::helpers::deserialize_one_or_many, }; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use url::Url; @@ -34,7 +34,7 @@ pub struct UpdateCommunity { #[async_trait::async_trait] impl InCommunity for UpdateCommunity { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let community: ApubCommunity = self.object.id.clone().dereference(context).await?; if let Some(audience) = &self.audience { verify_community_matches(audience, community.actor_id.clone())?; diff --git a/crates/apub/src/protocol/activities/create_or_update/note.rs b/crates/apub/src/protocol/activities/create_or_update/note.rs index 6fabc0aaa..ff0728174 100644 --- a/crates/apub/src/protocol/activities/create_or_update/note.rs +++ b/crates/apub/src/protocol/activities/create_or_update/note.rs @@ -11,7 +11,7 @@ use activitypub_federation::{ }; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{source::community::Community, traits::Crud}; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use url::Url; @@ -34,7 +34,7 @@ pub struct CreateOrUpdateNote { #[async_trait::async_trait] impl InCommunity for CreateOrUpdateNote { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let post = self.object.get_parents(context).await?.0; let community = Community::read(&mut context.pool(), post.community_id).await?; if let Some(audience) = &self.audience { diff --git a/crates/apub/src/protocol/activities/create_or_update/page.rs b/crates/apub/src/protocol/activities/create_or_update/page.rs index ec64c31a0..21052a9ef 100644 --- a/crates/apub/src/protocol/activities/create_or_update/page.rs +++ b/crates/apub/src/protocol/activities/create_or_update/page.rs @@ -9,7 +9,7 @@ use activitypub_federation::{ protocol::helpers::deserialize_one_or_many, }; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use url::Url; @@ -30,7 +30,7 @@ pub struct CreateOrUpdatePage { #[async_trait::async_trait] impl InCommunity for CreateOrUpdatePage { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let community = self.object.community(context).await?; if let Some(audience) = &self.audience { verify_community_matches(audience, community.actor_id.clone())?; diff --git a/crates/apub/src/protocol/activities/deletion/delete.rs b/crates/apub/src/protocol/activities/deletion/delete.rs index aefcf3f5f..3a29da069 100644 --- a/crates/apub/src/protocol/activities/deletion/delete.rs +++ b/crates/apub/src/protocol/activities/deletion/delete.rs @@ -15,7 +15,7 @@ use lemmy_db_schema::{ source::{community::Community, post::Post}, traits::Crud, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use url::Url; @@ -47,7 +47,7 @@ pub struct Delete { #[async_trait::async_trait] impl InCommunity for Delete { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let community_id = match DeletableObjects::read_from_db(self.object.id(), context).await? { DeletableObjects::Community(c) => c.id, DeletableObjects::Comment(c) => { diff --git a/crates/apub/src/protocol/activities/deletion/undo_delete.rs b/crates/apub/src/protocol/activities/deletion/undo_delete.rs index 35d9951b1..508b90113 100644 --- a/crates/apub/src/protocol/activities/deletion/undo_delete.rs +++ b/crates/apub/src/protocol/activities/deletion/undo_delete.rs @@ -10,7 +10,7 @@ use activitypub_federation::{ protocol::helpers::deserialize_one_or_many, }; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use url::Url; @@ -35,7 +35,7 @@ pub struct UndoDelete { #[async_trait::async_trait] impl InCommunity for UndoDelete { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let community = self.object.community(context).await?; if let Some(audience) = &self.audience { verify_community_matches(audience, community.actor_id.clone())?; diff --git a/crates/apub/src/protocol/activities/voting/undo_vote.rs b/crates/apub/src/protocol/activities/voting/undo_vote.rs index 746ae68df..e9ccbd593 100644 --- a/crates/apub/src/protocol/activities/voting/undo_vote.rs +++ b/crates/apub/src/protocol/activities/voting/undo_vote.rs @@ -5,7 +5,7 @@ use crate::{ }; use activitypub_federation::{config::Data, fetch::object_id::ObjectId, kinds::activity::UndoType}; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use url::Url; @@ -22,7 +22,7 @@ pub struct UndoVote { #[async_trait::async_trait] impl InCommunity for UndoVote { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let community = self.object.community(context).await?; if let Some(audience) = &self.audience { verify_community_matches(audience, community.actor_id.clone())?; diff --git a/crates/apub/src/protocol/activities/voting/vote.rs b/crates/apub/src/protocol/activities/voting/vote.rs index 013c15bfd..b632333c7 100644 --- a/crates/apub/src/protocol/activities/voting/vote.rs +++ b/crates/apub/src/protocol/activities/voting/vote.rs @@ -6,7 +6,7 @@ use crate::{ }; use activitypub_federation::{config::Data, fetch::object_id::ObjectId}; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult}; use serde::{Deserialize, Serialize}; use strum_macros::Display; use url::Url; @@ -51,7 +51,7 @@ impl From<&VoteType> for i16 { #[async_trait::async_trait] impl InCommunity for Vote { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let community = self .object .dereference(context) diff --git a/crates/apub/src/protocol/collections/empty_outbox.rs b/crates/apub/src/protocol/collections/empty_outbox.rs index 3801c04e9..1e7a4c6a8 100644 --- a/crates/apub/src/protocol/collections/empty_outbox.rs +++ b/crates/apub/src/protocol/collections/empty_outbox.rs @@ -1,5 +1,5 @@ use activitypub_federation::kinds::collection::OrderedCollectionType; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use url::Url; @@ -14,7 +14,7 @@ pub(crate) struct EmptyOutbox { } impl EmptyOutbox { - pub(crate) fn new(outbox_id: Url) -> Result { + pub(crate) fn new(outbox_id: Url) -> LemmyResult { Ok(EmptyOutbox { r#type: OrderedCollectionType::OrderedCollection, id: outbox_id, diff --git a/crates/apub/src/protocol/mod.rs b/crates/apub/src/protocol/mod.rs index d538ee531..a4774ac1d 100644 --- a/crates/apub/src/protocol/mod.rs +++ b/crates/apub/src/protocol/mod.rs @@ -7,7 +7,7 @@ use activitypub_federation::{ }; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::newtypes::DbUrl; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::collections::HashMap; use url::Url; @@ -71,7 +71,7 @@ impl IdOrNestedObject { IdOrNestedObject::NestedObject(n) => n.object_id(), } } - pub(crate) async fn object(self, context: &Data) -> Result { + pub(crate) async fn object(self, context: &Data) -> LemmyResult { match self { // TODO: move IdOrNestedObject struct to library and make fetch_object_http private IdOrNestedObject::Id(i) => Ok(fetch_object_http(&i, context).await?.object), @@ -83,25 +83,25 @@ impl IdOrNestedObject { #[async_trait::async_trait] pub trait InCommunity { // TODO: after we use audience field and remove backwards compat, it should be possible to change - // this to simply `fn community(&self) -> Result, LemmyError>` - async fn community(&self, context: &Data) -> Result; + // this to simply `fn community(&self) -> LemmyResult>` + async fn community(&self, context: &Data) -> LemmyResult; } #[cfg(test)] pub(crate) mod tests { use activitypub_federation::protocol::context::WithContext; use assert_json_diff::assert_json_include; - use lemmy_utils::error::LemmyError; + use lemmy_utils::error::LemmyResult; use serde::{de::DeserializeOwned, Serialize}; use std::{collections::HashMap, fs::File, io::BufReader}; - pub(crate) fn file_to_json_object(path: &str) -> Result { + pub(crate) fn file_to_json_object(path: &str) -> LemmyResult { let file = File::open(path)?; let reader = BufReader::new(file); Ok(serde_json::from_reader(reader)?) } - pub(crate) fn test_json(path: &str) -> Result, LemmyError> { + pub(crate) fn test_json(path: &str) -> LemmyResult> { file_to_json_object::>(path) } @@ -109,7 +109,7 @@ pub(crate) mod tests { /// Ensures that there are no breaking changes in sent data. pub(crate) fn test_parse_lemmy_item( path: &str, - ) -> Result { + ) -> LemmyResult { // parse file as T let parsed = file_to_json_object::(path)?; diff --git a/crates/apub/src/protocol/objects/group.rs b/crates/apub/src/protocol/objects/group.rs index 2a625a5a7..30cfafb17 100644 --- a/crates/apub/src/protocol/objects/group.rs +++ b/crates/apub/src/protocol/objects/group.rs @@ -26,7 +26,7 @@ use activitypub_federation::{ use chrono::{DateTime, Utc}; use lemmy_api_common::{context::LemmyContext, utils::local_site_opt_to_slur_regex}; use lemmy_utils::{ - error::LemmyError, + error::LemmyResult, utils::slurs::{check_slurs, check_slurs_opt}, }; use serde::{Deserialize, Serialize}; @@ -76,7 +76,7 @@ impl Group { &self, expected_domain: &Url, context: &LemmyContext, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { check_apub_id_valid_with_strictness(self.id.inner(), true, context).await?; verify_domains_match(expected_domain, self.id.inner())?; diff --git a/crates/apub/src/protocol/objects/mod.rs b/crates/apub/src/protocol/objects/mod.rs index 03229f739..efda3d7ed 100644 --- a/crates/apub/src/protocol/objects/mod.rs +++ b/crates/apub/src/protocol/objects/mod.rs @@ -4,7 +4,7 @@ use lemmy_db_schema::{ source::language::Language, utils::DbPool, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use url::Url; @@ -34,7 +34,7 @@ impl LanguageTag { pub(crate) async fn new_single( lang: LanguageId, pool: &mut DbPool<'_>, - ) -> Result, LemmyError> { + ) -> LemmyResult> { let lang = Language::read_from_id(pool, lang).await?; // undetermined @@ -51,7 +51,7 @@ impl LanguageTag { pub(crate) async fn new_multiple( lang_ids: Vec, pool: &mut DbPool<'_>, - ) -> Result, LemmyError> { + ) -> LemmyResult> { let mut langs = Vec::::new(); for l in lang_ids { @@ -71,7 +71,7 @@ impl LanguageTag { pub(crate) async fn to_language_id_single( lang: Option, pool: &mut DbPool<'_>, - ) -> Result, LemmyError> { + ) -> LemmyResult> { let identifier = lang.map(|l| l.identifier); let language = Language::read_id_from_code(pool, identifier.as_deref()).await?; @@ -81,7 +81,7 @@ impl LanguageTag { pub(crate) async fn to_language_id_multiple( langs: Vec, pool: &mut DbPool<'_>, - ) -> Result, LemmyError> { + ) -> LemmyResult> { let mut language_ids = Vec::new(); for l in langs { diff --git a/crates/apub/src/protocol/objects/note.rs b/crates/apub/src/protocol/objects/note.rs index 259a8fcfa..a092cec9f 100644 --- a/crates/apub/src/protocol/objects/note.rs +++ b/crates/apub/src/protocol/objects/note.rs @@ -20,7 +20,7 @@ use lemmy_db_schema::{ source::{community::Community, post::Post}, traits::Crud, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use std::ops::Deref; @@ -57,7 +57,7 @@ impl Note { pub(crate) async fn get_parents( &self, context: &Data, - ) -> Result<(ApubPost, Option), LemmyError> { + ) -> LemmyResult<(ApubPost, Option)> { // Fetch parent comment chain in a box, otherwise it can cause a stack overflow. let parent = Box::pin(self.in_reply_to.dereference(context).await?); match parent.deref() { @@ -73,7 +73,7 @@ impl Note { #[async_trait::async_trait] impl InCommunity for Note { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let (post, _) = self.get_parents(context).await?; let community = Community::read(&mut context.pool(), post.community_id).await?; if let Some(audience) = &self.audience { diff --git a/crates/apub/src/protocol/objects/page.rs b/crates/apub/src/protocol/objects/page.rs index 170778297..acfd8f5fd 100644 --- a/crates/apub/src/protocol/objects/page.rs +++ b/crates/apub/src/protocol/objects/page.rs @@ -20,7 +20,7 @@ use activitypub_federation::{ use chrono::{DateTime, Utc}; use itertools::Itertools; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult}; use serde::{de::Error, Deserialize, Deserializer, Serialize}; use serde_with::skip_serializing_none; use url::Url; @@ -160,10 +160,7 @@ impl Page { /// it is a mod action and needs to be verified as such. /// /// Locked needs to be false on a newly created post (verified in [[CreatePost]]. - pub(crate) async fn is_mod_action( - &self, - context: &Data, - ) -> Result { + pub(crate) async fn is_mod_action(&self, context: &Data) -> LemmyResult { let old_post = self.id.clone().dereference_local(context).await; Ok(Page::is_locked_changed(&old_post, &self.comments_enabled)) } @@ -181,7 +178,7 @@ impl Page { false } - pub(crate) fn creator(&self) -> Result, LemmyError> { + pub(crate) fn creator(&self) -> LemmyResult> { match &self.attributed_to { AttributedTo::Lemmy(l) => Ok(l.clone()), AttributedTo::Peertube(p) => p @@ -224,10 +221,10 @@ impl ActivityHandler for Page { fn actor(&self) -> &Url { unimplemented!() } - async fn verify(&self, data: &Data) -> Result<(), LemmyError> { + async fn verify(&self, data: &Data) -> LemmyResult<()> { ApubPost::verify(self, self.id.inner(), data).await } - async fn receive(self, data: &Data) -> Result<(), LemmyError> { + async fn receive(self, data: &Data) -> LemmyResult<()> { ApubPost::from_json(self, data).await?; Ok(()) } @@ -235,7 +232,7 @@ impl ActivityHandler for Page { #[async_trait::async_trait] impl InCommunity for Page { - async fn community(&self, context: &Data) -> Result { + async fn community(&self, context: &Data) -> LemmyResult { let community = match &self.attributed_to { AttributedTo::Lemmy(_) => { let mut iter = self.to.iter().merge(self.cc.iter()); diff --git a/crates/db_schema/src/impls/actor_language.rs b/crates/db_schema/src/impls/actor_language.rs index 0191dd872..fe21cf003 100644 --- a/crates/db_schema/src/impls/actor_language.rs +++ b/crates/db_schema/src/impls/actor_language.rs @@ -26,7 +26,7 @@ use diesel::{ QueryDsl, }; use diesel_async::{AsyncPgConnection, RunQueryDsl}; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::{LemmyErrorType, LemmyResult}; use tokio::sync::OnceCell; pub const UNDETERMINED_ID: LanguageId = LanguageId(0); @@ -194,7 +194,7 @@ impl CommunityLanguage { pool: &mut DbPool<'_>, for_language_id: Option, for_community_id: CommunityId, - ) -> Result<(), LemmyError> { + ) -> LemmyResult<()> { use crate::schema::community_language::dsl::community_language; let conn = &mut get_conn(pool).await?; diff --git a/crates/db_schema/src/impls/local_site.rs b/crates/db_schema/src/impls/local_site.rs index 90b25fed5..39ed624ef 100644 --- a/crates/db_schema/src/impls/local_site.rs +++ b/crates/db_schema/src/impls/local_site.rs @@ -1,23 +1,23 @@ use crate::{ - schema::local_site::dsl::local_site, + schema::local_site, source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm}, utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error}; use diesel_async::RunQueryDsl; -use lemmy_utils::{error::LemmyError, CACHE_DURATION_API}; +use lemmy_utils::{error::LemmyResult, CACHE_DURATION_API}; use moka::future::Cache; use once_cell::sync::Lazy; impl LocalSite { pub async fn create(pool: &mut DbPool<'_>, form: &LocalSiteInsertForm) -> Result { let conn = &mut get_conn(pool).await?; - insert_into(local_site) + insert_into(local_site::table) .values(form) .get_result::(conn) .await } - pub async fn read(pool: &mut DbPool<'_>) -> Result { + pub async fn read(pool: &mut DbPool<'_>) -> LemmyResult { static CACHE: Lazy> = Lazy::new(|| { Cache::builder() .max_capacity(1) @@ -28,20 +28,20 @@ impl LocalSite { CACHE .try_get_with((), async { let conn = &mut get_conn(pool).await?; - local_site.first::(conn).await + local_site::table.first::(conn).await }) .await?, ) } pub async fn update(pool: &mut DbPool<'_>, form: &LocalSiteUpdateForm) -> Result { let conn = &mut get_conn(pool).await?; - diesel::update(local_site) + diesel::update(local_site::table) .set(form) .get_result::(conn) .await } pub async fn delete(pool: &mut DbPool<'_>) -> Result { let conn = &mut get_conn(pool).await?; - diesel::delete(local_site).execute(conn).await + diesel::delete(local_site::table).execute(conn).await } } diff --git a/crates/db_schema/src/impls/private_message.rs b/crates/db_schema/src/impls/private_message.rs index 8370d5d08..e3ad03972 100644 --- a/crates/db_schema/src/impls/private_message.rs +++ b/crates/db_schema/src/impls/private_message.rs @@ -9,7 +9,7 @@ use crate::{ use chrono::{DateTime, Utc}; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use url::Url; #[async_trait] @@ -74,7 +74,7 @@ impl PrivateMessage { pub async fn read_from_apub_id( pool: &mut DbPool<'_>, object_id: Url, - ) -> Result, LemmyError> { + ) -> LemmyResult> { let conn = &mut get_conn(pool).await?; let object_id: DbUrl = object_id.into(); Ok( diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 465ecb4cd..f0b294c04 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -31,7 +31,7 @@ use diesel_migrations::EmbeddedMigrations; use futures_util::{future::BoxFuture, Future, FutureExt}; use i_love_jesus::CursorKey; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, settings::SETTINGS, }; use once_cell::sync::Lazy; @@ -292,9 +292,7 @@ pub fn diesel_option_overwrite(opt: Option) -> Option> { } } -pub fn diesel_option_overwrite_to_url( - opt: &Option, -) -> Result>, LemmyError> { +pub fn diesel_option_overwrite_to_url(opt: &Option) -> LemmyResult>> { match opt.as_ref().map(String::as_str) { // An empty string is an erase Some("") => Ok(Some(None)), @@ -305,9 +303,7 @@ pub fn diesel_option_overwrite_to_url( } } -pub fn diesel_option_overwrite_to_url_create( - opt: &Option, -) -> Result, LemmyError> { +pub fn diesel_option_overwrite_to_url_create(opt: &Option) -> LemmyResult> { match opt.as_ref().map(String::as_str) { // An empty string is nothing Some("") => Ok(None), @@ -365,7 +361,7 @@ impl ServerCertVerifier for NoCertVerifier { pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!(); -fn run_migrations(db_url: &str) -> Result<(), LemmyError> { +fn run_migrations(db_url: &str) -> LemmyResult<()> { // Needs to be a sync connection let mut conn = PgConnection::establish(db_url).with_context(|| "Error connecting to database")?; @@ -378,7 +374,7 @@ fn run_migrations(db_url: &str) -> Result<(), LemmyError> { Ok(()) } -pub async fn build_db_pool() -> Result { +pub async fn build_db_pool() -> LemmyResult { let db_url = SETTINGS.get_database_url(); // We only support TLS with sslmode=require currently let tls_enabled = db_url.contains("sslmode=require"); diff --git a/crates/routes/src/feeds.rs b/crates/routes/src/feeds.rs index b8ca2d5a6..2c29f192e 100644 --- a/crates/routes/src/feeds.rs +++ b/crates/routes/src/feeds.rs @@ -22,7 +22,7 @@ use lemmy_db_views_actor::{ }; use lemmy_utils::{ cache_header::cache_1hour, - error::{LemmyError, LemmyErrorType}, + error::{LemmyError, LemmyErrorType, LemmyResult}, utils::markdown::{markdown_to_html, sanitize_html}, }; use once_cell::sync::Lazy; @@ -151,7 +151,7 @@ async fn get_feed_data( sort_type: SortType, limit: i64, page: i64, -) -> Result { +) -> LemmyResult { let site_view = SiteView::read_local(&mut context.pool()).await?; check_private_instance(&None, &site_view.local_site)?; @@ -256,7 +256,7 @@ async fn get_feed_user( limit: &i64, page: &i64, user_name: &str, -) -> Result { +) -> LemmyResult { let site_view = SiteView::read_local(&mut context.pool()).await?; let person = Person::read_from_name(&mut context.pool(), user_name, false).await?; @@ -292,7 +292,7 @@ async fn get_feed_community( limit: &i64, page: &i64, community_name: &str, -) -> Result { +) -> LemmyResult { let site_view = SiteView::read_local(&mut context.pool()).await?; let community = Community::read_from_name(&mut context.pool(), community_name, false).await?; if community.visibility != CommunityVisibility::Public { @@ -335,7 +335,7 @@ async fn get_feed_front( limit: &i64, page: &i64, jwt: &str, -) -> Result { +) -> LemmyResult { let site_view = SiteView::read_local(&mut context.pool()).await?; let local_user = local_user_view_from_jwt(jwt, context).await?; @@ -370,7 +370,7 @@ async fn get_feed_front( } #[tracing::instrument(skip_all)] -async fn get_feed_inbox(context: &LemmyContext, jwt: &str) -> Result { +async fn get_feed_inbox(context: &LemmyContext, jwt: &str) -> LemmyResult { let site_view = SiteView::read_local(&mut context.pool()).await?; let local_user = local_user_view_from_jwt(jwt, context).await?; let person_id = local_user.local_user.person_id; @@ -425,7 +425,7 @@ fn create_reply_and_mention_items( replies: Vec, mentions: Vec, protocol_and_hostname: &str, -) -> Result, LemmyError> { +) -> LemmyResult> { let mut reply_items: Vec = replies .iter() .map(|r| { @@ -438,7 +438,7 @@ fn create_reply_and_mention_items( protocol_and_hostname, ) }) - .collect::, LemmyError>>()?; + .collect::>>()?; let mut mention_items: Vec = mentions .iter() @@ -452,7 +452,7 @@ fn create_reply_and_mention_items( protocol_and_hostname, ) }) - .collect::, LemmyError>>()?; + .collect::>>()?; reply_items.append(&mut mention_items); Ok(reply_items) @@ -465,7 +465,7 @@ fn build_item( url: &str, content: &str, protocol_and_hostname: &str, -) -> Result { +) -> LemmyResult { // TODO add images let author_url = format!("{protocol_and_hostname}/u/{creator_name}"); let guid = Some(Guid { @@ -489,10 +489,7 @@ fn build_item( } #[tracing::instrument(skip_all)] -fn create_post_items( - posts: Vec, - protocol_and_hostname: &str, -) -> Result, LemmyError> { +fn create_post_items(posts: Vec, protocol_and_hostname: &str) -> LemmyResult> { let mut items: Vec = Vec::new(); for p in posts { diff --git a/crates/routes/src/lib.rs b/crates/routes/src/lib.rs index ec28fda45..a88225622 100644 --- a/crates/routes/src/lib.rs +++ b/crates/routes/src/lib.rs @@ -1,6 +1,6 @@ use lemmy_api_common::{claims::Claims, context::LemmyContext, utils::check_user_valid}; use lemmy_db_views::structs::LocalUserView; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; pub mod feeds; pub mod images; @@ -8,10 +8,7 @@ pub mod nodeinfo; pub mod webfinger; #[tracing::instrument(skip_all)] -async fn local_user_view_from_jwt( - jwt: &str, - context: &LemmyContext, -) -> Result { +async fn local_user_view_from_jwt(jwt: &str, context: &LemmyContext) -> LemmyResult { let local_user_id = Claims::validate(jwt, context).await?; let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?; check_user_valid(&local_user_view.person)?; diff --git a/crates/routes/src/nodeinfo.rs b/crates/routes/src/nodeinfo.rs index 62082b4c8..b5db4e965 100644 --- a/crates/routes/src/nodeinfo.rs +++ b/crates/routes/src/nodeinfo.rs @@ -5,7 +5,7 @@ use lemmy_db_schema::RegistrationMode; use lemmy_db_views::structs::SiteView; use lemmy_utils::{ cache_header::{cache_1hour, cache_3days}, - error::LemmyError, + error::{LemmyError, LemmyResult}, VERSION, }; use serde::{Deserialize, Serialize}; @@ -24,9 +24,7 @@ pub fn config(cfg: &mut web::ServiceConfig) { ); } -async fn node_info_well_known( - context: web::Data, -) -> Result { +async fn node_info_well_known(context: web::Data) -> LemmyResult { let node_info = NodeInfoWellKnown { links: vec![NodeInfoWellKnownLinks { rel: Url::parse("http://nodeinfo.diaspora.software/ns/schema/2.0")?, diff --git a/crates/routes/src/webfinger.rs b/crates/routes/src/webfinger.rs index 95092b244..36dd97079 100644 --- a/crates/routes/src/webfinger.rs +++ b/crates/routes/src/webfinger.rs @@ -9,7 +9,7 @@ use lemmy_db_schema::{ traits::ApubActor, CommunityVisibility, }; -use lemmy_utils::{cache_header::cache_3days, error::LemmyError}; +use lemmy_utils::{cache_header::cache_3days, error::LemmyResult}; use serde::Deserialize; use std::collections::HashMap; use url::Url; @@ -35,7 +35,7 @@ pub fn config(cfg: &mut web::ServiceConfig) { async fn get_webfinger_response( info: Query, context: Data, -) -> Result { +) -> LemmyResult { let name = extract_webfinger_name(&info.resource, &context)?; let links = if name == context.settings().hostname { diff --git a/crates/utils/src/email.rs b/crates/utils/src/email.rs index 1a786b0ef..7bac7ad67 100644 --- a/crates/utils/src/email.rs +++ b/crates/utils/src/email.rs @@ -1,5 +1,5 @@ use crate::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, settings::structs::Settings, }; use html2text; @@ -25,7 +25,7 @@ pub async fn send_email( to_username: &str, html: &str, settings: &Settings, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let email_config = settings.email.clone().ok_or(LemmyErrorType::NoEmailSetup)?; let domain = settings.hostname.clone(); diff --git a/crates/utils/src/error.rs b/crates/utils/src/error.rs index d25845894..cc6897edd 100644 --- a/crates/utils/src/error.rs +++ b/crates/utils/src/error.rs @@ -244,11 +244,11 @@ cfg_if! { } pub trait LemmyErrorExt> { - fn with_lemmy_type(self, error_type: LemmyErrorType) -> Result; + fn with_lemmy_type(self, error_type: LemmyErrorType) -> LemmyResult; } impl> LemmyErrorExt for Result { - fn with_lemmy_type(self, error_type: LemmyErrorType) -> Result { + fn with_lemmy_type(self, error_type: LemmyErrorType) -> LemmyResult { self.map_err(|error| LemmyError { error_type, inner: error.into(), @@ -257,12 +257,12 @@ cfg_if! { } } pub trait LemmyErrorExt2 { - fn with_lemmy_type(self, error_type: LemmyErrorType) -> Result; + fn with_lemmy_type(self, error_type: LemmyErrorType) -> LemmyResult; fn into_anyhow(self) -> Result; } - impl LemmyErrorExt2 for Result { - fn with_lemmy_type(self, error_type: LemmyErrorType) -> Result { + impl LemmyErrorExt2 for LemmyResult { + fn with_lemmy_type(self, error_type: LemmyErrorType) -> LemmyResult { self.map_err(|mut e| { e.error_type = error_type; e diff --git a/crates/utils/src/settings/mod.rs b/crates/utils/src/settings/mod.rs index d0f802e5b..6efa3fdd3 100644 --- a/crates/utils/src/settings/mod.rs +++ b/crates/utils/src/settings/mod.rs @@ -1,4 +1,4 @@ -use crate::{error::LemmyError, location_info}; +use crate::{error::LemmyResult, location_info}; use anyhow::{anyhow, Context}; use deser_hjson::from_str; use once_cell::sync::Lazy; @@ -38,7 +38,7 @@ impl Settings { /// Note: The env var `LEMMY_DATABASE_URL` is parsed in /// `lemmy_db_schema/src/lib.rs::get_database_url_from_env()` /// Warning: Only call this once. - pub(crate) fn init() -> Result { + pub(crate) fn init() -> LemmyResult { let config = from_str::(&Self::read_config_file()?)?; if config.hostname == "unset" { Err(anyhow!("Hostname variable is not set!").into()) @@ -108,7 +108,7 @@ impl Settings { WEBFINGER_REGEX.clone() } - pub fn pictrs_config(&self) -> Result { + pub fn pictrs_config(&self) -> LemmyResult { self .pictrs .clone() diff --git a/crates/utils/src/utils/slurs.rs b/crates/utils/src/utils/slurs.rs index e379ae439..c7c8a88e3 100644 --- a/crates/utils/src/utils/slurs.rs +++ b/crates/utils/src/utils/slurs.rs @@ -1,4 +1,4 @@ -use crate::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; +use crate::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; use regex::{Regex, RegexBuilder}; pub fn remove_slurs(test: &str, slur_regex: &Option) -> String { @@ -39,7 +39,7 @@ pub fn build_slur_regex(regex_str: Option<&str>) -> Option { }) } -pub fn check_slurs(text: &str, slur_regex: &Option) -> Result<(), LemmyError> { +pub fn check_slurs(text: &str, slur_regex: &Option) -> LemmyResult<()> { if let Err(slurs) = slur_check(text, slur_regex) { Err(anyhow::anyhow!("{}", slurs_vec_to_str(&slurs))).with_lemmy_type(LemmyErrorType::Slurs) } else { @@ -47,10 +47,7 @@ pub fn check_slurs(text: &str, slur_regex: &Option) -> Result<(), LemmyEr } } -pub fn check_slurs_opt( - text: &Option, - slur_regex: &Option, -) -> Result<(), LemmyError> { +pub fn check_slurs_opt(text: &Option, slur_regex: &Option) -> LemmyResult<()> { match text { Some(t) => check_slurs(t, slur_regex), None => Ok(()), diff --git a/src/code_migrations.rs b/src/code_migrations.rs index cee02075c..a2325971b 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -34,14 +34,14 @@ use lemmy_db_schema::{ traits::Crud, utils::{get_conn, naive_now, DbPool}, }; -use lemmy_utils::{error::LemmyError, settings::structs::Settings}; +use lemmy_utils::{error::LemmyResult, settings::structs::Settings}; use tracing::info; use url::Url; pub async fn run_advanced_migrations( pool: &mut DbPool<'_>, settings: &Settings, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { let protocol_and_hostname = &settings.get_protocol_and_hostname(); user_updates_2020_04_02(pool, protocol_and_hostname).await?; community_updates_2020_04_02(pool, protocol_and_hostname).await?; @@ -60,7 +60,7 @@ pub async fn run_advanced_migrations( async fn user_updates_2020_04_02( pool: &mut DbPool<'_>, protocol_and_hostname: &str, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { use lemmy_db_schema::schema::person::dsl::{actor_id, local, person}; let conn = &mut get_conn(pool).await?; @@ -99,7 +99,7 @@ async fn user_updates_2020_04_02( async fn community_updates_2020_04_02( pool: &mut DbPool<'_>, protocol_and_hostname: &str, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { use lemmy_db_schema::schema::community::dsl::{actor_id, community, local}; let conn = &mut get_conn(pool).await?; @@ -139,7 +139,7 @@ async fn community_updates_2020_04_02( async fn post_updates_2020_04_03( pool: &mut DbPool<'_>, protocol_and_hostname: &str, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { use lemmy_db_schema::schema::post::dsl::{ap_id, local, post}; let conn = &mut get_conn(pool).await?; @@ -177,7 +177,7 @@ async fn post_updates_2020_04_03( async fn comment_updates_2020_04_03( pool: &mut DbPool<'_>, protocol_and_hostname: &str, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { use lemmy_db_schema::schema::comment::dsl::{ap_id, comment, local}; let conn = &mut get_conn(pool).await?; @@ -215,7 +215,7 @@ async fn comment_updates_2020_04_03( async fn private_message_updates_2020_05_05( pool: &mut DbPool<'_>, protocol_and_hostname: &str, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { use lemmy_db_schema::schema::private_message::dsl::{ap_id, local, private_message}; let conn = &mut get_conn(pool).await?; @@ -253,7 +253,7 @@ async fn private_message_updates_2020_05_05( async fn post_thumbnail_url_updates_2020_07_27( pool: &mut DbPool<'_>, protocol_and_hostname: &str, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { use lemmy_db_schema::schema::post::dsl::{post, thumbnail_url}; let conn = &mut get_conn(pool).await?; @@ -282,10 +282,7 @@ async fn post_thumbnail_url_updates_2020_07_27( /// We are setting inbox and follower URLs for local and remote actors alike, because for now /// all federated instances are also Lemmy and use the same URL scheme. -async fn apub_columns_2021_02_02( - pool: &mut DbPool<'_>, - settings: &Settings, -) -> Result<(), LemmyError> { +async fn apub_columns_2021_02_02(pool: &mut DbPool<'_>, settings: &Settings) -> LemmyResult<()> { let conn = &mut get_conn(pool).await?; info!("Running apub_columns_2021_02_02"); { @@ -346,7 +343,7 @@ async fn instance_actor_2022_01_28( pool: &mut DbPool<'_>, protocol_and_hostname: &str, settings: &Settings, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { info!("Running instance_actor_2021_09_29"); if let Ok(site_view) = SiteView::read_local(pool).await { let site = site_view.site; @@ -374,7 +371,7 @@ async fn instance_actor_2022_01_28( /// key field is empty, generate a new keypair. It would be possible to regenerate only the pubkey, /// but thats more complicated and has no benefit, as federation is already broken for these actors. /// https://github.com/LemmyNet/lemmy/issues/2347 -async fn regenerate_public_keys_2022_07_05(pool: &mut DbPool<'_>) -> Result<(), LemmyError> { +async fn regenerate_public_keys_2022_07_05(pool: &mut DbPool<'_>) -> LemmyResult<()> { let conn = &mut get_conn(pool).await?; info!("Running regenerate_public_keys_2022_07_05"); @@ -433,7 +430,7 @@ async fn regenerate_public_keys_2022_07_05(pool: &mut DbPool<'_>) -> Result<(), async fn initialize_local_site_2022_10_10( pool: &mut DbPool<'_>, settings: &Settings, -) -> Result<(), LemmyError> { +) -> LemmyResult<()> { info!("Running initialize_local_site_2022_10_10"); // Check to see if local_site exists diff --git a/src/lib.rs b/src/lib.rs index 777c5d9ce..00960826a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,6 @@ use actix_web::{ App, HttpResponse, HttpServer, - Result, }; use actix_web_prom::PrometheusMetricsBuilder; use clap::Parser; @@ -45,7 +44,7 @@ use lemmy_db_schema::{source::secret::Secret, utils::build_db_pool}; use lemmy_federate::{start_stop_federation_workers_cancellable, Opts}; use lemmy_routes::{feeds, images, nodeinfo, webfinger}; use lemmy_utils::{ - error::LemmyError, + error::LemmyResult, rate_limit::RateLimitCell, response::jsonify_plain_text_errors, settings::{structs::Settings, SETTINGS}, @@ -107,7 +106,7 @@ pub struct CmdArgs { } /// Placing the main function in lib.rs allows other crates to import it and embed Lemmy -pub async fn start_lemmy_server(args: CmdArgs) -> Result<(), LemmyError> { +pub async fn start_lemmy_server(args: CmdArgs) -> LemmyResult<()> { // Print version number to log println!("Lemmy v{VERSION}"); @@ -244,7 +243,7 @@ pub async fn start_lemmy_server(args: CmdArgs) -> Result<(), LemmyError> { } /// Creates temporary HTTP server which returns status 503 for all requests. -fn create_startup_server() -> Result { +fn create_startup_server() -> LemmyResult { let startup_server = HttpServer::new(move || { App::new().wrap(ErrorHandlers::new().default_handler(move |req| { let (req, _) = req.into_parts(); @@ -267,7 +266,7 @@ fn create_http_server( federation_config: FederationConfig, settings: Settings, federation_enabled: bool, -) -> Result { +) -> LemmyResult { // this must come before the HttpServer creation // creates a middleware that populates http metrics for each path, method, and status code let prom_api_metrics = PrometheusMetricsBuilder::new("lemmy_api") @@ -349,7 +348,7 @@ fn cors_config(settings: &Settings) -> Cors { } } -pub fn init_logging(opentelemetry_url: &Option) -> Result<(), LemmyError> { +pub fn init_logging(opentelemetry_url: &Option) -> LemmyResult<()> { LogTracer::init()?; let log_description = env::var("RUST_LOG").unwrap_or_else(|_| "info".into()); diff --git a/src/main.rs b/src/main.rs index 1544bcecf..dd17d6eb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,9 @@ use clap::Parser; use lemmy_server::{init_logging, start_lemmy_server, CmdArgs}; -use lemmy_utils::{error::LemmyError, settings::SETTINGS}; +use lemmy_utils::{error::LemmyResult, settings::SETTINGS}; #[tokio::main] -pub async fn main() -> Result<(), LemmyError> { +pub async fn main() -> LemmyResult<()> { init_logging(&SETTINGS.opentelemetry_url)?; let args = CmdArgs::parse(); diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index e225b96ff..8c4cf9311 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -29,13 +29,13 @@ use lemmy_db_schema::{ utils::{get_conn, naive_now, now, DbPool, DELETED_REPLACEMENT_TEXT}, }; use lemmy_routes::nodeinfo::NodeInfo; -use lemmy_utils::error::{LemmyError, LemmyResult}; +use lemmy_utils::error::LemmyResult; use reqwest_middleware::ClientWithMiddleware; use std::time::Duration; use tracing::{error, info, warn}; /// Schedules various cleanup tasks for lemmy in a background thread -pub async fn setup(context: LemmyContext) -> Result<(), LemmyError> { +pub async fn setup(context: LemmyContext) -> LemmyResult<()> { // Setup the connections let mut scheduler = AsyncScheduler::new(); startup_jobs(&mut context.pool()).await; diff --git a/src/telemetry.rs b/src/telemetry.rs index 2f758e062..a7a1ac809 100644 --- a/src/telemetry.rs +++ b/src/telemetry.rs @@ -1,5 +1,5 @@ use console_subscriber::ConsoleLayer; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::LemmyResult; use opentelemetry::{ sdk::{propagation::TraceContextPropagator, Resource}, KeyValue, @@ -8,11 +8,7 @@ use opentelemetry_otlp::WithExportConfig; use tracing::{subscriber::set_global_default, Subscriber}; use tracing_subscriber::{filter::Targets, layer::SubscriberExt, registry::LookupSpan, Layer}; -pub fn init_tracing( - opentelemetry_url: &str, - subscriber: S, - targets: Targets, -) -> Result<(), LemmyError> +pub fn init_tracing(opentelemetry_url: &str, subscriber: S, targets: Targets) -> LemmyResult<()> where S: Subscriber + for<'a> LookupSpan<'a> + Send + Sync + 'static, {