use crate::filters::parser::parser_error::FilterParserErrorContext;
use crate::io::error::IOError;
use crate::io::http::error::HttpClientError;
use crate::manager::models::FilterId;
use crate::storage::error::DatabaseError;
use std::fmt::Display;
#[cfg_attr(test, derive(PartialEq))]
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum FLMError {
#[error(transparent)]
Database(DatabaseError),
#[error("Entity `{0}` not found")]
EntityNotFound(i64),
#[error(transparent)]
Io(IOError),
#[error(transparent)]
Network(HttpClientError),
#[error(transparent)]
ParseFilterError(FilterParserErrorContext),
#[error("FieldEmpty: {0}")]
FieldIsEmpty(&'static str),
#[error("InvalidConfiguration: {0}")]
InvalidConfiguration(&'static str),
#[error("Filter integrity check failed for filter_id={0}")]
FilterIntegrityCheckFailed(FilterId),
#[error("{0}")]
Other(String),
}
impl FLMError {
#[inline]
pub(crate) fn from_database(error: rusqlite::Error) -> Self {
Self::Database(error.into())
}
#[inline]
pub(crate) fn from_io(error: std::io::Error) -> Self {
Self::Io(error.into())
}
#[inline]
pub(crate) fn make_err<T>(error: impl Into<String>) -> Result<T, Self> {
Err(Self::from_str(error))
}
#[inline]
pub(crate) fn from_str(error: impl Into<String>) -> Self {
Self::Other(error.into())
}
#[inline]
pub(crate) fn from_display<T>(err: T) -> Self
where
T: Display,
{
Self::Other(err.to_string())
}
#[inline]
pub(crate) fn from_parser_error(error: FilterParserErrorContext) -> Self {
Self::ParseFilterError(error)
}
}
impl From<rusqlite::Error> for FLMError {
fn from(value: rusqlite::Error) -> Self {
Self::from_database(value)
}
}