diff --git a/crates/utils/src/error.rs b/crates/utils/src/error.rs index 4e634bde3..d805ecf0f 100644 --- a/crates/utils/src/error.rs +++ b/crates/utils/src/error.rs @@ -1,6 +1,6 @@ use cfg_if::cfg_if; use serde::{Deserialize, Serialize}; -use std::{backtrace::Backtrace, fmt::Debug}; +use std::fmt::Debug; use strum::{Display, EnumIter}; #[derive(Display, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, EnumIter, Hash)] @@ -23,19 +23,14 @@ pub enum LemmyErrorType { CouldntUpdateComment, CouldntUpdatePrivateMessage, CannotLeaveAdmin, - NoLinesInHtml, - SiteMetadataPageIsNotDoctypeHtml, PictrsResponseError(String), PictrsPurgeResponseError(String), - PictrsCachingDisabled, ImageUrlMissingPathSegments, ImageUrlMissingLastPathSegment, PictrsApiKeyNotProvided, NoContentTypeHeader, NotAnImageType, NotAModOrAdmin, - NoAdmins, - NotTopAdmin, NotTopMod, NotLoggedIn, NotHigherMod, @@ -84,18 +79,15 @@ pub enum LemmyErrorType { RegistrationClosed, RegistrationApplicationAnswerRequired, EmailAlreadyExists, - FederationForbiddenByStrictAllowList, PersonIsBannedFromCommunity, ObjectIsNotPublic, InvalidCommunity, CannotCreatePostOrCommentInDeletedOrRemovedCommunity, CannotReceivePage, - NewPostCannotBeLocked, OnlyLocalAdminCanRemoveCommunity, OnlyLocalAdminCanRestoreCommunity, NoIdGiven, IncorrectLogin, - InvalidQuery, ObjectNotLocal, PostIsLocked, PersonIsBannedFromSite(String), @@ -138,7 +130,6 @@ pub enum LemmyErrorType { CouldntUpdateCommunity, CouldntUpdateReplies, CouldntUpdatePersonMentions, - PostTitleTooLong, CouldntCreatePost, CouldntCreatePrivateMessage, CouldntUpdatePrivate, diff --git a/crates/utils/tests/test_errors_used.rs b/crates/utils/tests/test_errors_used.rs new file mode 100644 index 000000000..5324ee45a --- /dev/null +++ b/crates/utils/tests/test_errors_used.rs @@ -0,0 +1,28 @@ +use lemmy_utils::LemmyErrorType; +use std::{env::current_dir, process::Command}; +use strum::IntoEnumIterator; + +#[test] +fn test_errors_used() { + let mut unused_error_found = false; + let mut current_dir = current_dir().unwrap(); + current_dir.pop(); + current_dir.pop(); + for error in LemmyErrorType::iter() { + let mut command = Command::new("grep"); + let command = command + .current_dir(current_dir.clone()) + .arg("-R") + .arg("--exclude=error.rs") + .arg(error.to_string()) + .arg("crates/") + .arg("src/"); + let output = command.output().unwrap(); + let stdout = std::str::from_utf8(&output.stdout).unwrap(); + if stdout.len() == 0 { + println!("LemmyErrorType::{} is unused", error); + unused_error_found = true; + } + } + assert!(unused_error_found == false); +}