mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 15:52:27 +00:00
split store and store_sqlite implementatio into multiple crates
This commit is contained in:
51
crates/store_sqlite/src/error.rs
Normal file
51
crates/store_sqlite/src/error.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("Not found")]
|
||||
NotFound,
|
||||
|
||||
#[error("Resource already exists and overwrite=false")]
|
||||
AlreadyExists,
|
||||
|
||||
#[error("Invalid ics/vcf input: {0}")]
|
||||
InvalidData(String),
|
||||
|
||||
#[error(transparent)]
|
||||
SqlxError(sqlx::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
Other(#[from] anyhow::Error),
|
||||
}
|
||||
|
||||
impl From<sqlx::Error> for Error {
|
||||
fn from(value: sqlx::Error) -> Self {
|
||||
match value {
|
||||
sqlx::Error::RowNotFound => Error::NotFound,
|
||||
err => Error::SqlxError(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: clean up error types
|
||||
impl From<Error> for rustical_store::Error {
|
||||
fn from(value: Error) -> Self {
|
||||
match value {
|
||||
Error::NotFound => Self::NotFound,
|
||||
Error::AlreadyExists => Self::AlreadyExists,
|
||||
Error::InvalidData(b) => Self::InvalidData(b),
|
||||
Error::SqlxError(err) => Self::Other(err.into()),
|
||||
Error::Other(err) => Self::Other(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rustical_store::Error> for Error {
|
||||
fn from(value: rustical_store::Error) -> Self {
|
||||
match value {
|
||||
rustical_store::Error::NotFound => Self::NotFound,
|
||||
rustical_store::Error::AlreadyExists => Self::AlreadyExists,
|
||||
rustical_store::Error::InvalidData(b) => Self::InvalidData(b),
|
||||
rustical_store::Error::Other(err) => Self::Other(err),
|
||||
rustical_store::Error::ParserError(err) => Self::Other(err.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user