2025-05-03 11:17:38 +09:00
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
|
|
pub enum Error {
|
2025-05-08 06:33:08 +09:00
|
|
|
#[error("IO error")]
|
|
|
|
Io(#[from] std::io::Error),
|
2025-05-04 11:10:14 +09:00
|
|
|
#[error("Parse int error")]
|
|
|
|
ParseInt(#[from] std::num::ParseIntError),
|
2025-05-13 08:54:15 +09:00
|
|
|
#[error("Password hash error")]
|
|
|
|
PasswordHash(String),
|
2025-05-08 06:33:08 +09:00
|
|
|
#[error("Deserialize toml error")]
|
2025-05-03 11:17:38 +09:00
|
|
|
TomlDe(#[from] toml::de::Error),
|
2025-05-08 06:33:08 +09:00
|
|
|
#[error("Serialize toml error")]
|
|
|
|
TomlSer(#[from] toml::ser::Error),
|
2025-05-03 11:17:38 +09:00
|
|
|
#[error("Missing config value: ({0})")]
|
2025-05-08 06:33:08 +09:00
|
|
|
MissingConfig(String),
|
|
|
|
#[error("Cannot get default config directory")]
|
|
|
|
DefaultConfigDir,
|
|
|
|
#[error("Uninitialized global var: {0}")]
|
|
|
|
UninitializedOnceCell(String),
|
|
|
|
#[error("Once cell is initializing: {0}")]
|
|
|
|
InitializingOnceCell(String),
|
|
|
|
#[error("Once cell is already Initialized: {0}")]
|
|
|
|
AlreadyInitializedOnceCell(String),
|
2025-05-15 07:28:06 +09:00
|
|
|
#[cfg(feature="desktop")]
|
2025-05-08 06:33:08 +09:00
|
|
|
#[error("DB Error: {0}")]
|
|
|
|
Db(#[from]sea_orm::DbErr),
|
|
|
|
}
|
2025-05-03 11:17:38 +09:00
|
|
|
|
2025-05-08 06:33:08 +09:00
|
|
|
impl<T> From<tokio::sync::SetError<T>> for Error{
|
|
|
|
fn from(e: tokio::sync::SetError<T>) -> Self {
|
|
|
|
match e {
|
|
|
|
tokio::sync::SetError::AlreadyInitializedError(_) => Self::AlreadyInitializedOnceCell(std::any::type_name::<T>().to_string()),
|
|
|
|
tokio::sync::SetError::InitializingError(_) => Self::InitializingOnceCell(std::any::type_name::<T>().to_string())
|
|
|
|
}
|
|
|
|
}
|
2025-05-03 11:17:38 +09:00
|
|
|
}
|