proof_of_sql/sql/
error.rs

1use 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/// Errors related to queries that can not be run due to invalid column references, data types, etc.
11/// Will be replaced once we fully switch to the planner.
12#[derive(Snafu, Debug, PartialEq, Eq)]
13pub enum AnalyzeError {
14    #[snafu(display("Expression has datatype {expr_type}, which was not valid"))]
15    /// Invalid data type received
16    InvalidDataType {
17        /// data type found
18        expr_type: ColumnType,
19    },
20
21    #[snafu(display("Left side has '{left_type}' type but right side has '{right_type}' type"))]
22    /// Data types do not match
23    DataTypeMismatch {
24        /// The left side datatype
25        left_type: String,
26        /// The right side datatype
27        right_type: String,
28    },
29
30    #[snafu(display("Columns have different lengths: {len_a} != {len_b}"))]
31    /// Two columns do not have the same length
32    DifferentColumnLength {
33        /// The length of the first column
34        len_a: usize,
35        /// The length of the second column
36        len_b: usize,
37    },
38
39    #[snafu(transparent)]
40    /// Errors related to decimal operations
41    DecimalConversionError {
42        /// The underlying source error
43        source: DecimalError,
44    },
45
46    #[snafu(transparent)]
47    /// Errors related to placeholders
48    PlaceholderError {
49        /// The underlying source error
50        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
68/// Result type for analyze errors
69pub type AnalyzeResult<T> = Result<T, AnalyzeError>;