use nemo_flow::plugin::PluginError;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum AdaptiveError {
#[error("invalid config: {0}")]
InvalidConfig(String),
#[error("not found: {0}")]
NotFound(String),
#[error("storage error: {0}")]
Storage(String),
#[error("serialization error: {0}")]
Serialization(serde_json::Error),
#[error("internal error: {0}")]
Internal(String),
#[error("registration failed: {0}")]
RegistrationFailed(String),
#[error("channel closed: {0}")]
ChannelClosed(String),
#[cfg(feature = "redis-backend")]
#[error("redis error: {0}")]
Redis(#[from] redis::RedisError),
}
impl From<serde_json::Error> for AdaptiveError {
fn from(value: serde_json::Error) -> Self {
Self::Serialization(value)
}
}
impl From<PluginError> for AdaptiveError {
fn from(value: PluginError) -> Self {
match value {
PluginError::InvalidConfig(message) => Self::InvalidConfig(message),
PluginError::NotFound(message) => Self::NotFound(message),
PluginError::Serialization(err) => Self::Serialization(err),
PluginError::Internal(message) => Self::Internal(message),
PluginError::RegistrationFailed(message) => Self::RegistrationFailed(message),
}
}
}
pub type Result<T> = std::result::Result<T, AdaptiveError>;
#[cfg(test)]
#[path = "../tests/coverage/error_tests.rs"]
mod tests;