proof_of_sql/sql/
error.rs1use crate::base::{
2    database::ColumnType,
3    math::decimal::{DecimalError, IntermediateDecimalError},
4    proof::PlaceholderError,
5};
6use alloc::string::{String, ToString};
7use core::result::Result;
8use snafu::Snafu;
9
10#[derive(Snafu, Debug, PartialEq, Eq)]
13pub enum AnalyzeError {
14    #[snafu(display("Expression has datatype {expr_type}, which was not valid"))]
15    InvalidDataType {
17        expr_type: ColumnType,
19    },
20
21    #[snafu(display("Left side has '{left_type}' type but right side has '{right_type}' type"))]
22    DataTypeMismatch {
24        left_type: String,
26        right_type: String,
28    },
29
30    #[snafu(display("Columns have different lengths: {len_a} != {len_b}"))]
31    DifferentColumnLength {
33        len_a: usize,
35        len_b: usize,
37    },
38
39    #[snafu(transparent)]
40    DecimalConversionError {
42        source: DecimalError,
44    },
45
46    #[snafu(transparent)]
47    PlaceholderError {
49        source: PlaceholderError,
51    },
52}
53
54impl From<AnalyzeError> for String {
55    fn from(error: AnalyzeError) -> Self {
56        error.to_string()
57    }
58}
59
60impl From<IntermediateDecimalError> for AnalyzeError {
61    fn from(err: IntermediateDecimalError) -> AnalyzeError {
62        AnalyzeError::DecimalConversionError {
63            source: DecimalError::IntermediateDecimalConversionError { source: err },
64        }
65    }
66}
67
68pub type AnalyzeResult<T> = Result<T, AnalyzeError>;