use crate::base::{
database::ColumnType,
math::decimal::{DecimalError, IntermediateDecimalError},
proof::PlaceholderError,
};
use alloc::string::{String, ToString};
use core::result::Result;
use snafu::Snafu;
#[derive(Snafu, Debug, PartialEq, Eq)]
pub enum AnalyzeError {
#[snafu(display("Expression has datatype {expr_type}, which was not valid"))]
InvalidDataType {
expr_type: ColumnType,
},
#[snafu(display("Left side has '{left_type}' type but right side has '{right_type}' type"))]
DataTypeMismatch {
left_type: String,
right_type: String,
},
#[snafu(display("Columns have different lengths: {len_a} != {len_b}"))]
DifferentColumnLength {
len_a: usize,
len_b: usize,
},
#[snafu(transparent)]
DecimalConversionError {
source: DecimalError,
},
#[snafu(transparent)]
PlaceholderError {
source: PlaceholderError,
},
#[snafu(display("Not enough input plans"))]
NotEnoughInputPlans,
}
impl From<AnalyzeError> for String {
fn from(error: AnalyzeError) -> Self {
error.to_string()
}
}
impl From<IntermediateDecimalError> for AnalyzeError {
fn from(err: IntermediateDecimalError) -> AnalyzeError {
AnalyzeError::DecimalConversionError {
source: DecimalError::IntermediateDecimalConversionError { source: err },
}
}
}
pub type AnalyzeResult<T> = Result<T, AnalyzeError>;