chore (backend-rs): remove 'Err' suffix from error variants

https://rust-lang.github.io/rust-clippy/master/index.html#/enum_variant_names
This commit is contained in:
naskya 2024-05-23 20:49:49 +09:00
parent 55ed733df8
commit 85d44aaa2d
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
14 changed files with 64 additions and 64 deletions

View file

@ -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]

View file

@ -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<RedisError>),
Bb8Pool(RunError<RedisError>),
}
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

View file

@ -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,
}

View file

@ -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<ImageSize, Error> {
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<ImageSize, Error> {
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()?;

View file

@ -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<String, Error> {
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(),
));
}

View file

@ -15,11 +15,11 @@ pub fn hash_password(password: &str) -> Result<String, password_hash::errors::Er
#[derive(thiserror::Error, Debug)]
pub enum VerifyError {
#[error("An error occured while bcrypt verification: {0}")]
BcryptErr(#[from] bcrypt::BcryptError),
Bcrypt(#[from] bcrypt::BcryptError),
#[error("Invalid argon2 password hash: {0}")]
InvalidArgon2Hash(#[from] password_hash::Error),
#[error("An error occured while argon2 verification: {0}")]
Argon2Err(#[from] argon2::Error),
Argon2(#[from] argon2::Error),
}
#[crate::export]

View file

@ -59,9 +59,9 @@ pub fn count_reactions(reactions: &HashMap<String, u32>) -> HashMap<String, u32>
#[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]

View file

@ -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

View file

@ -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,
}

View file

@ -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> {

View file

@ -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<IsahcWebPushClient> = 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(),
));
}

View file

@ -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()

View file

@ -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<HttpClient> = OnceCell::new();

View file

@ -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<i64, InvalidIdErr> {
pub fn get_timestamp(id: &str) -> Result<i64, InvalidIdError> {
let n: Option<u64> = 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() })
}
}