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("Expected '{expected}' but found '{actual}'"))]
15    /// Invalid data type received
16    InvalidDataType {
17        /// Expected data type
18        expected: ColumnType,
19        /// Actual data type found
20        actual: ColumnType,
21    },
22
23    #[snafu(display("Left side has '{left_type}' type but right side has '{right_type}' type"))]
24    /// Data types do not match
25    DataTypeMismatch {
26        /// The left side datatype
27        left_type: String,
28        /// The right side datatype
29        right_type: String,
30    },
31
32    #[snafu(display("Columns have different lengths: {len_a} != {len_b}"))]
33    /// Two columns do not have the same length
34    DifferentColumnLength {
35        /// The length of the first column
36        len_a: usize,
37        /// The length of the second column
38        len_b: usize,
39    },
40
41    #[snafu(transparent)]
42    /// Errors related to decimal operations
43    DecimalConversionError {
44        /// The underlying source error
45        source: DecimalError,
46    },
47
48    #[snafu(transparent)]
49    /// Errors related to placeholders
50    PlaceholderError {
51        /// The underlying source error
52        source: PlaceholderError,
53    },
54}
55
56impl From<AnalyzeError> for String {
57    fn from(error: AnalyzeError) -> Self {
58        error.to_string()
59    }
60}
61
62impl From<IntermediateDecimalError> for AnalyzeError {
63    fn from(err: IntermediateDecimalError) -> AnalyzeError {
64        AnalyzeError::DecimalConversionError {
65            source: DecimalError::IntermediateDecimalConversionError { source: err },
66        }
67    }
68}
69
70/// Result type for analyze errors
71pub type AnalyzeResult<T> = Result<T, AnalyzeError>;