From bc2f7c6826ee25d4f728471e55747972143a8ff5 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Wed, 1 May 2024 22:36:15 -0700 Subject: [PATCH] enable `enum_variant_names` lint --- Cargo.toml | 3 --- src/api/server_server.rs | 2 +- src/service/pdu.rs | 2 +- src/utils/error.rs | 28 ++++++++++++++-------------- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 624c9157..c4b3d64d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,9 +48,6 @@ unseparated_literal_suffix = "warn" verbose_file_reads = "warn" wildcard_dependencies = "warn" -# TODO: Remove these -enum_variant_names = "allow" - [package] name = "grapevine" description = "A Matrix homeserver written in Rust" diff --git a/src/api/server_server.rs b/src/api/server_server.rs index 32a9b7f4..cc1ebbd3 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -306,7 +306,7 @@ where }) } else { debug!("Returning error from {destination}"); - Err(Error::FederationError( + Err(Error::Federation( destination.to_owned(), RumaError::from_http_response(http_response), )) diff --git a/src/service/pdu.rs b/src/service/pdu.rs index d535fc3f..ec192c78 100644 --- a/src/service/pdu.rs +++ b/src/service/pdu.rs @@ -61,7 +61,7 @@ impl PduEvent { let mut content = serde_json::from_str(self.content.get()) .map_err(|_| Error::bad_database("PDU in db has invalid content."))?; redact_content_in_place(&mut content, &room_version_id, self.kind.to_string()) - .map_err(|e| Error::RedactionError(self.sender.server_name().to_owned(), e))?; + .map_err(|e| Error::Redaction(self.sender.server_name().to_owned(), e))?; self.unsigned = Some(to_raw_value(&json!({ "redacted_because": serde_json::to_value(reason).expect("to_value(PduEvent) always works") diff --git a/src/utils/error.rs b/src/utils/error.rs index f9c5b4ea..d05a9a28 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -19,35 +19,35 @@ pub(crate) type Result = std::result::Result; pub(crate) enum Error { #[cfg(feature = "sqlite")] #[error("There was a problem with the connection to the sqlite database: {source}")] - SqliteError { + Sqlite { #[from] source: rusqlite::Error, }, #[cfg(feature = "rocksdb")] #[error("There was a problem with the connection to the rocksdb database: {source}")] - RocksDbError { + RocksDb { #[from] source: rocksdb::Error, }, #[error("Could not generate an image.")] - ImageError { + Image { #[from] source: image::error::ImageError, }, #[error("Could not connect to server: {source}")] - ReqwestError { + Reqwest { #[from] source: reqwest::Error, }, #[error("Could build regular expression: {source}")] - RegexError { + Regex { #[from] source: regex::Error, }, #[error("{0}")] - FederationError(OwnedServerName, RumaError), + Federation(OwnedServerName, RumaError), #[error("Could not do this io: {source}")] - IoError { + Io { #[from] source: std::io::Error, }, @@ -65,13 +65,13 @@ pub(crate) enum Error { #[error("{0}")] Conflict(&'static str), // This is only needed for when a room alias already exists #[error("{0}")] - ExtensionError(#[from] axum::extract::rejection::ExtensionRejection), + Extension(#[from] axum::extract::rejection::ExtensionRejection), #[error("{0}")] - PathError(#[from] axum::extract::rejection::PathRejection), + Path(#[from] axum::extract::rejection::PathRejection), #[error("{0}")] AdminCommand(&'static str), #[error("from {0}: {1}")] - RedactionError(OwnedServerName, ruma::canonical_json::RedactionError), + Redaction(OwnedServerName, ruma::canonical_json::RedactionError), #[error("{0} in {1}")] InconsistentRoomState(&'static str, ruma::OwnedRoomId), } @@ -94,7 +94,7 @@ impl Error { return RumaResponse(UiaaResponse::AuthResponse(uiaainfo.clone())); } - if let Self::FederationError(origin, error) = self { + if let Self::Federation(origin, error) = self { let mut error = error.clone(); error.body = ErrorBody::Standard { kind: Unknown, @@ -141,10 +141,10 @@ impl Error { match self { #[cfg(feature = "sqlite")] - Self::SqliteError { .. } => db_error, + Self::Sqlite { .. } => db_error, #[cfg(feature = "rocksdb")] - Self::RocksDbError { .. } => db_error, - Self::IoError { .. } => db_error, + Self::RocksDb { .. } => db_error, + Self::Io { .. } => db_error, Self::BadConfig { .. } => db_error, Self::BadDatabase { .. } => db_error, _ => self.to_string(),