move repos into monorepo
This commit is contained in:
46
lib/osiris/core/error.rs
Normal file
46
lib/osiris/core/error.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Redis(redis::RedisError),
|
||||
Serialization(serde_json::Error),
|
||||
NotFound(String),
|
||||
InvalidInput(String),
|
||||
Config(String),
|
||||
Io(std::io::Error),
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Error::Redis(e) => write!(f, "Redis error: {}", e),
|
||||
Error::Serialization(e) => write!(f, "Serialization error: {}", e),
|
||||
Error::NotFound(msg) => write!(f, "Not found: {}", msg),
|
||||
Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
|
||||
Error::Config(msg) => write!(f, "Configuration error: {}", msg),
|
||||
Error::Io(e) => write!(f, "IO error: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl From<redis::RedisError> for Error {
|
||||
fn from(e: redis::RedisError) -> Self {
|
||||
Error::Redis(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for Error {
|
||||
fn from(e: serde_json::Error) -> Self {
|
||||
Error::Serialization(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(e: std::io::Error) -> Self {
|
||||
Error::Io(e)
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
Reference in New Issue
Block a user