proof_of_sql/sql/
error.rs

1use crate::base::{
2    database::ColumnType,
3    math::decimal::{DecimalError, IntermediateDecimalError},
4};
5use alloc::string::{String, ToString};
6use core::result::Result;
7use snafu::Snafu;
8
9/// Errors related to queries that can not be run due to invalid column references, data types, etc.
10/// Will be replaced once we fully switch to the planner.
11#[derive(Snafu, Debug, PartialEq, Eq)]
12pub enum AnalyzeError {
13    #[snafu(display("Expected '{expected}' but found '{actual}'"))]
14    /// Invalid data type received
15    InvalidDataType {
16        /// Expected data type
17        expected: ColumnType,
18        /// Actual data type found
19        actual: ColumnType,
20    },
21
22    #[snafu(display("Left side has '{left_type}' type but right side has '{right_type}' type"))]
23    /// Data types do not match
24    DataTypeMismatch {
25        /// The left side datatype
26        left_type: String,
27        /// The right side datatype
28        right_type: String,
29    },
30
31    #[snafu(display("Columns have different lengths: {len_a} != {len_b}"))]
32    /// Two columns do not have the same length
33    DifferentColumnLength {
34        /// The length of the first column
35        len_a: usize,
36        /// The length of the second column
37        len_b: usize,
38    },
39
40    #[snafu(transparent)]
41    /// Errors related to decimal operations
42    DecimalConversionError {
43        /// The underlying source error
44        source: DecimalError,
45    },
46}
47
48impl From<AnalyzeError> for String {
49    fn from(error: AnalyzeError) -> Self {
50        error.to_string()
51    }
52}
53
54impl From<IntermediateDecimalError> for AnalyzeError {
55    fn from(err: IntermediateDecimalError) -> AnalyzeError {
56        AnalyzeError::DecimalConversionError {
57            source: DecimalError::IntermediateDecimalConversionError { source: err },
58        }
59    }
60}
61
62/// Result type for analyze errors
63pub type AnalyzeResult<T> = Result<T, AnalyzeError>;