use std::fmt;
#[derive(Debug)]
pub enum TableError {
NoWritePolicyError,
JsonError,
FileOpError(std::io::Error),
SerdeError(serde_json::Error),
AppendLengthError,
PushError(String),
PopError(String),
}
impl fmt::Display for TableError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::FileOpError(e) => write!(f, "{e}"),
Self::JsonError => write!(f, "Non Json file in Table"),
Self::SerdeError(e) => write!(f, "{e}"),
Self::NoWritePolicyError => {
write!(
f,
"You are trying to modify a Table without permission to do so"
)
}
Self::AppendLengthError => {
write!(f, "Not equal lengths of file names and elements")
}
Self::PushError(s) => {
write!(
f,
"File {s}.json already exists in table and can't be pushed into the table"
)
}
Self::PopError(s) => {
write!(f, "File {s}.json doesn't exist in the table")
} }
}
}
impl std::error::Error for TableError {}
impl From<std::io::Error> for TableError {
fn from(e: std::io::Error) -> Self {
Self::FileOpError(e)
}
}
impl From<serde_json::Error> for TableError {
fn from(e: serde_json::Error) -> Self {
Self::SerdeError(e)
}
}
#[derive(Debug)]
pub enum TableBuilderError {
DirCreateError(std::io::Error),
CreateWithoutWriteError,
TableAlreadyExistsError,
}
impl fmt::Display for TableBuilderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DirCreateError(e) => write!(f, "{e}"),
Self::CreateWithoutWriteError => {
write!(f, "Tried to create a table without write policy")
}
Self::TableAlreadyExistsError => {
write!(f, "The table already exists, try loading it instead")
}
}
}
}
impl std::error::Error for TableBuilderError {}
impl From<std::io::Error> for TableBuilderError {
fn from(e: std::io::Error) -> Self {
TableBuilderError::DirCreateError(e)
}
}