use thiserror::Error;
pub type AnalyzerResult<T> = Result<T, AnalyzerError>;
#[derive(Error, Debug)]
pub enum AnalyzerError {
#[error("Failed to compute state: {0}")]
StateComputation(String),
#[error("Failed to compute metric: {0}")]
MetricComputation(String),
#[error("Failed to merge states: {0}")]
StateMerge(String),
#[error("Query execution failed: {0}")]
QueryExecution(#[from] datafusion::error::DataFusionError),
#[error("Arrow computation failed: {0}")]
ArrowComputation(#[from] arrow::error::ArrowError),
#[error("Invalid configuration: {0}")]
InvalidConfiguration(String),
#[error("Invalid data: {0}")]
InvalidData(String),
#[error("No data available for analysis")]
NoData,
#[error("Serialization error: {0}")]
Serialization(String),
#[error("{0}")]
Custom(String),
}
impl AnalyzerError {
pub fn state_computation(msg: impl Into<String>) -> Self {
Self::StateComputation(msg.into())
}
pub fn metric_computation(msg: impl Into<String>) -> Self {
Self::MetricComputation(msg.into())
}
pub fn state_merge(msg: impl Into<String>) -> Self {
Self::StateMerge(msg.into())
}
pub fn invalid_config(msg: impl Into<String>) -> Self {
Self::InvalidConfiguration(msg.into())
}
pub fn invalid_data(msg: impl Into<String>) -> Self {
Self::InvalidData(msg.into())
}
pub fn custom(msg: impl Into<String>) -> Self {
Self::Custom(msg.into())
}
pub fn execution(msg: impl Into<String>) -> Self {
Self::Custom(format!("Execution error: {}", msg.into()))
}
pub fn internal(msg: impl Into<String>) -> Self {
Self::Custom(format!("Internal error: {}", msg.into()))
}
}
impl From<serde_json::Error> for AnalyzerError {
fn from(err: serde_json::Error) -> Self {
Self::Serialization(err.to_string())
}
}