From 85d44aaa2dac2aee6d41b9e069d490c2f784f3a4 Mon Sep 17 00:00:00 2001 From: naskya Date: Thu, 23 May 2024 20:49:49 +0900 Subject: [PATCH] chore (backend-rs): remove 'Err' suffix from error variants https://rust-lang.github.io/rust-clippy/master/index.html#/enum_variant_names --- packages/backend-rs/src/database/cache.rs | 8 ++++---- packages/backend-rs/src/database/redis.rs | 8 ++++---- packages/backend-rs/src/misc/convert_host.rs | 4 ++-- .../backend-rs/src/misc/get_image_size.rs | 20 +++++++++---------- .../backend-rs/src/misc/latest_version.rs | 14 ++++++------- packages/backend-rs/src/misc/password.rs | 4 ++-- packages/backend-rs/src/misc/reaction.rs | 4 ++-- .../src/service/antenna/add_new_note.rs | 16 +++++++-------- .../backend-rs/src/service/nodeinfo/fetch.rs | 8 ++++---- .../src/service/nodeinfo/generate.rs | 6 +++--- .../src/service/push_notification.rs | 16 +++++++-------- packages/backend-rs/src/service/stream.rs | 10 +++++----- packages/backend-rs/src/util/http_client.rs | 4 ++-- packages/backend-rs/src/util/id.rs | 6 +++--- 14 files changed, 64 insertions(+), 64 deletions(-) diff --git a/packages/backend-rs/src/database/cache.rs b/packages/backend-rs/src/database/cache.rs index dd0509a31a..abc90ef2d1 100644 --- a/packages/backend-rs/src/database/cache.rs +++ b/packages/backend-rs/src/database/cache.rs @@ -18,13 +18,13 @@ pub enum Category { #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Redis error: {0}")] - RedisErr(#[from] RedisError), + Redis(#[from] RedisError), #[error("Redis connection error: {0}")] - RedisConnErr(#[from] RedisConnError), + RedisConn(#[from] RedisConnError), #[error("Data serialization error: {0}")] - SerializeErr(#[from] rmp_serde::encode::Error), + Serialize(#[from] rmp_serde::encode::Error), #[error("Data deserialization error: {0}")] - DeserializeErr(#[from] rmp_serde::decode::Error), + Deserialize(#[from] rmp_serde::decode::Error), } #[inline] diff --git a/packages/backend-rs/src/database/redis.rs b/packages/backend-rs/src/database/redis.rs index e152ff0f40..2ef0499bb5 100644 --- a/packages/backend-rs/src/database/redis.rs +++ b/packages/backend-rs/src/database/redis.rs @@ -80,9 +80,9 @@ async fn init_conn_pool() -> Result<(), RedisError> { #[derive(thiserror::Error, Debug)] pub enum RedisConnError { #[error("Failed to initialize Redis connection pool: {0}")] - RedisErr(RedisError), + Redis(RedisError), #[error("Redis connection pool error: {0}")] - Bb8PoolErr(RunError), + Bb8Pool(RunError), } pub async fn redis_conn( @@ -91,7 +91,7 @@ pub async fn redis_conn( let init_res = init_conn_pool().await; if let Err(err) = init_res { - return Err(RedisConnError::RedisErr(err)); + return Err(RedisConnError::Redis(err)); } } @@ -100,7 +100,7 @@ pub async fn redis_conn( .unwrap() .get() .await - .map_err(RedisConnError::Bb8PoolErr) + .map_err(RedisConnError::Bb8Pool) } /// prefix redis key diff --git a/packages/backend-rs/src/misc/convert_host.rs b/packages/backend-rs/src/misc/convert_host.rs index d6770ecc74..2a88ce7ccd 100644 --- a/packages/backend-rs/src/misc/convert_host.rs +++ b/packages/backend-rs/src/misc/convert_host.rs @@ -3,9 +3,9 @@ use crate::config::CONFIG; #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Idna error: {0}")] - IdnaErr(#[from] idna::Errors), + Idna(#[from] idna::Errors), #[error("Url parse error: {0}")] - UrlParseErr(#[from] url::ParseError), + UrlParse(#[from] url::ParseError), #[error("Hostname is missing")] NoHostname, } diff --git a/packages/backend-rs/src/misc/get_image_size.rs b/packages/backend-rs/src/misc/get_image_size.rs index c2fc6f9073..c1348e62c3 100644 --- a/packages/backend-rs/src/misc/get_image_size.rs +++ b/packages/backend-rs/src/misc/get_image_size.rs @@ -9,23 +9,23 @@ use tokio::sync::Mutex; #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Redis cache error: {0}")] - CacheErr(#[from] cache::Error), + Cache(#[from] cache::Error), #[error("HTTP client aquisition error: {0}")] - HttpClientErr(#[from] http_client::Error), + HttpClient(#[from] http_client::Error), #[error("Isahc error: {0}")] - IsahcErr(#[from] isahc::Error), + Isahc(#[from] isahc::Error), #[error("HTTP error: {0}")] - HttpErr(String), + Http(String), #[error("Image decoding error: {0}")] - ImageErr(#[from] ImageError), + Image(#[from] ImageError), #[error("Image decoding error: {0}")] - IoErr(#[from] std::io::Error), + Io(#[from] std::io::Error), #[error("Exif extraction error: {0}")] - ExifErr(#[from] nom_exif::Error), + Exif(#[from] nom_exif::Error), #[error("Emoji meta attempt limit exceeded: {0}")] TooManyAttempts(String), #[error("Unsupported image type: {0}")] - UnsupportedImageErr(String), + UnsupportedImage(String), } const BROWSER_SAFE_IMAGE_TYPES: [ImageFormat; 8] = [ @@ -76,7 +76,7 @@ pub async fn get_image_size_from_url(url: &str) -> Result { if !response.status().is_success() { tracing::info!("status: {}", response.status()); tracing::debug!("response body: {:#?}", response.body()); - return Err(Error::HttpErr(format!("Failed to get image from {}", url))); + return Err(Error::Http(format!("Failed to get image from {}", url))); } let image_bytes = response.bytes()?; @@ -85,7 +85,7 @@ pub async fn get_image_size_from_url(url: &str) -> Result { let format = reader.format(); if format.is_none() || !BROWSER_SAFE_IMAGE_TYPES.contains(&format.unwrap()) { - return Err(Error::UnsupportedImageErr(format!("{:?}", format))); + return Err(Error::UnsupportedImage(format!("{:?}", format))); } let size = reader.into_dimensions()?; diff --git a/packages/backend-rs/src/misc/latest_version.rs b/packages/backend-rs/src/misc/latest_version.rs index 69a5a961ab..544f922e53 100644 --- a/packages/backend-rs/src/misc/latest_version.rs +++ b/packages/backend-rs/src/misc/latest_version.rs @@ -6,17 +6,17 @@ use serde::{Deserialize, Serialize}; #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Cache error: {0}")] - CacheErr(#[from] cache::Error), + Cache(#[from] cache::Error), #[error("Isahc error: {0}")] - IsahcErr(#[from] isahc::Error), + Isahc(#[from] isahc::Error), #[error("HTTP client aquisition error: {0}")] - HttpClientErr(#[from] http_client::Error), + HttpClient(#[from] http_client::Error), #[error("HTTP error: {0}")] - HttpErr(String), + Http(String), #[error("Response parsing error: {0}")] - IoErr(#[from] std::io::Error), + Io(#[from] std::io::Error), #[error("Failed to deserialize JSON: {0}")] - JsonErr(#[from] serde_json::Error), + Json(#[from] serde_json::Error), } const UPSTREAM_PACKAGE_JSON_URL: &str = @@ -33,7 +33,7 @@ async fn get_latest_version() -> Result { if !response.status().is_success() { tracing::info!("status: {}", response.status()); tracing::debug!("response body: {:#?}", response.body()); - return Err(Error::HttpErr( + return Err(Error::Http( "Failed to fetch version from Firefish GitLab".to_string(), )); } diff --git a/packages/backend-rs/src/misc/password.rs b/packages/backend-rs/src/misc/password.rs index 8b8353ad4f..ecef7f6da8 100644 --- a/packages/backend-rs/src/misc/password.rs +++ b/packages/backend-rs/src/misc/password.rs @@ -15,11 +15,11 @@ pub fn hash_password(password: &str) -> Result) -> HashMap #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Idna error: {0}")] - IdnaErr(#[from] idna::Errors), + Idna(#[from] idna::Errors), #[error("Database error: {0}")] - DbErr(#[from] DbErr), + Db(#[from] DbErr), } #[crate::export] diff --git a/packages/backend-rs/src/service/antenna/add_new_note.rs b/packages/backend-rs/src/service/antenna/add_new_note.rs index 1d2d336766..683c22c506 100644 --- a/packages/backend-rs/src/service/antenna/add_new_note.rs +++ b/packages/backend-rs/src/service/antenna/add_new_note.rs @@ -4,26 +4,26 @@ use crate::misc::get_note_all_texts::{all_texts, NoteLike}; use crate::model::entity::{antenna, note}; use crate::service::antenna::check_hit::{check_hit_antenna, AntennaCheckError}; use crate::service::stream; -use crate::util::id::{get_timestamp, InvalidIdErr}; +use crate::util::id::{get_timestamp, InvalidIdError}; use redis::{streams::StreamMaxlen, AsyncCommands, RedisError}; use sea_orm::{DbErr, EntityTrait}; #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Database error: {0}")] - DbErr(#[from] DbErr), + Db(#[from] DbErr), #[error("Cache error: {0}")] - CacheErr(#[from] cache::Error), + Cache(#[from] cache::Error), #[error("Redis error: {0}")] - RedisErr(#[from] RedisError), + Redis(#[from] RedisError), #[error("Redis connection error: {0}")] - RedisConnErr(#[from] RedisConnError), + RedisConn(#[from] RedisConnError), #[error("Invalid ID: {0}")] - InvalidIdErr(#[from] InvalidIdErr), + InvalidId(#[from] InvalidIdError), #[error("Stream error: {0}")] - StreamErr(#[from] stream::Error), + Stream(#[from] stream::Error), #[error("Failed to check if the note should be added to antenna: {0}")] - AntennaCheckErr(#[from] AntennaCheckError), + AntennaCheck(#[from] AntennaCheckError), } // for napi export diff --git a/packages/backend-rs/src/service/nodeinfo/fetch.rs b/packages/backend-rs/src/service/nodeinfo/fetch.rs index ef38ae015a..7c781cd73d 100644 --- a/packages/backend-rs/src/service/nodeinfo/fetch.rs +++ b/packages/backend-rs/src/service/nodeinfo/fetch.rs @@ -6,15 +6,15 @@ use serde::{Deserialize, Serialize}; #[derive(thiserror::Error, Debug)] pub enum Error { #[error("HTTP client aquisition error: {0}")] - HttpClientErr(#[from] http_client::Error), + HttpClient(#[from] http_client::Error), #[error("HTTP error: {0}")] - HttpErr(#[from] isahc::Error), + Http(#[from] isahc::Error), #[error("Bad status: {0}")] BadStatus(String), #[error("Failed to parse response body as text: {0}")] - ResponseErr(#[from] std::io::Error), + Response(#[from] std::io::Error), #[error("Failed to parse response body as json: {0}")] - JsonErr(#[from] serde_json::Error), + Json(#[from] serde_json::Error), #[error("No nodeinfo provided")] MissingNodeinfo, } diff --git a/packages/backend-rs/src/service/nodeinfo/generate.rs b/packages/backend-rs/src/service/nodeinfo/generate.rs index 5d7b8b30c1..8976dc6a13 100644 --- a/packages/backend-rs/src/service/nodeinfo/generate.rs +++ b/packages/backend-rs/src/service/nodeinfo/generate.rs @@ -10,11 +10,11 @@ use std::collections::HashMap; #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Database error: {0}")] - DbErr(#[from] DbErr), + Db(#[from] DbErr), #[error("Cache error: {0}")] - CacheErr(#[from] cache::Error), + Cache(#[from] cache::Error), #[error("Failed to serialize nodeinfo to JSON: {0}")] - JsonErr(#[from] serde_json::Error), + Json(#[from] serde_json::Error), } async fn statistics() -> Result<(u64, u64, u64, u64), DbErr> { diff --git a/packages/backend-rs/src/service/push_notification.rs b/packages/backend-rs/src/service/push_notification.rs index 5bde31eb31..797b4cf5c1 100644 --- a/packages/backend-rs/src/service/push_notification.rs +++ b/packages/backend-rs/src/service/push_notification.rs @@ -13,15 +13,15 @@ use web_push::{ #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Database error: {0}")] - DbErr(#[from] DbErr), + Db(#[from] DbErr), #[error("Web Push error: {0}")] - WebPushErr(#[from] WebPushError), + WebPush(#[from] WebPushError), #[error("Failed to (de)serialize an object: {0}")] - SerializeErr(#[from] serde_json::Error), + Serialize(#[from] serde_json::Error), #[error("Invalid content: {0}")] - InvalidContentErr(String), + InvalidContent(String), #[error("HTTP client aquisition error: {0}")] - HttpClientErr(#[from] http_client::Error), + HttpClient(#[from] http_client::Error), } static CLIENT: OnceCell = OnceCell::new(); @@ -59,7 +59,7 @@ fn compact_content( } if !content.is_object() { - return Err(Error::InvalidContentErr("not a JSON object".to_string())); + return Err(Error::InvalidContent("not a JSON object".to_string())); } let object = content.as_object_mut().unwrap(); @@ -73,7 +73,7 @@ fn compact_content( .get("note") .unwrap() .get("renote") - .ok_or(Error::InvalidContentErr( + .ok_or(Error::InvalidContent( "renote object is missing".to_string(), ))? } else { @@ -82,7 +82,7 @@ fn compact_content( .clone(); if !note.is_object() { - return Err(Error::InvalidContentErr( + return Err(Error::InvalidContent( "(re)note is not an object".to_string(), )); } diff --git a/packages/backend-rs/src/service/stream.rs b/packages/backend-rs/src/service/stream.rs index d9437f3fa3..dc73499968 100644 --- a/packages/backend-rs/src/service/stream.rs +++ b/packages/backend-rs/src/service/stream.rs @@ -48,13 +48,13 @@ pub enum Stream { #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Redis error: {0}")] - RedisErr(#[from] RedisError), + Redis(#[from] RedisError), #[error("Redis connection error: {0}")] - RedisConnErr(#[from] RedisConnError), + RedisConn(#[from] RedisConnError), #[error("Json (de)serialization error: {0}")] - JsonErr(#[from] serde_json::Error), + Json(#[from] serde_json::Error), #[error("Value error: {0}")] - ValueErr(String), + Value(String), } pub async fn publish_to_stream( @@ -69,7 +69,7 @@ pub async fn publish_to_stream( value.unwrap_or("null".to_string()), ) } else { - value.ok_or(Error::ValueErr("Invalid streaming message".to_string()))? + value.ok_or(Error::Value("Invalid streaming message".to_string()))? }; redis_conn() diff --git a/packages/backend-rs/src/util/http_client.rs b/packages/backend-rs/src/util/http_client.rs index 97967fcfd1..bc5976c283 100644 --- a/packages/backend-rs/src/util/http_client.rs +++ b/packages/backend-rs/src/util/http_client.rs @@ -6,9 +6,9 @@ use std::time::Duration; #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Isahc error: {0}")] - IsahcErr(#[from] isahc::Error), + Isahc(#[from] isahc::Error), #[error("Url parse error: {0}")] - UrlParseErr(#[from] isahc::http::uri::InvalidUri), + UrlParse(#[from] isahc::http::uri::InvalidUri), } static CLIENT: OnceCell = OnceCell::new(); diff --git a/packages/backend-rs/src/util/id.rs b/packages/backend-rs/src/util/id.rs index 595a8ebb3a..416716076b 100644 --- a/packages/backend-rs/src/util/id.rs +++ b/packages/backend-rs/src/util/id.rs @@ -47,17 +47,17 @@ fn create_id(datetime: &NaiveDateTime) -> String { #[derive(thiserror::Error, Debug)] #[error("Invalid ID: {id}")] -pub struct InvalidIdErr { +pub struct InvalidIdError { id: String, } #[crate::export] -pub fn get_timestamp(id: &str) -> Result { +pub fn get_timestamp(id: &str) -> Result { let n: Option = BASE36.decode_var_len(&id[0..8]); if let Some(n) = n { Ok(n as i64 + TIME_2000) } else { - Err(InvalidIdErr { id: id.to_string() }) + Err(InvalidIdError { id: id.to_string() }) } }