Skip to main content

sql_builder/
error.rs

1//! Error types used in tideorm-sql-builder.
2
3/// A statement that cannot be rendered as SQL.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum RenderError {
6    /// The backend has no SQL for this, or the statement is incomplete.
7    Unsupported(String),
8    /// A numbered marker is zero, malformed, or too large to represent.
9    InvalidIndex(String),
10    /// A marker names an argument that was not supplied (one-based index).
11    MissingValue { index: usize, count: usize },
12    /// An argument has no corresponding marker (one-based index).
13    UnusedValue { index: usize },
14}
15
16impl std::error::Error for RenderError {}
17impl std::fmt::Display for RenderError {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        match self {
20            Self::Unsupported(message) => f.write_str(message),
21            Self::InvalidIndex(index) => write!(f, "invalid parameter index: {index}"),
22            Self::MissingValue { index, count } => {
23                write!(f, "parameter {index} has no value ({count} supplied)")
24            }
25            Self::UnusedValue { index } => write!(f, "parameter value {index} is unused"),
26        }
27    }
28}
29
30/// Result type for tideorm-sql-builder
31pub type Result<T> = std::result::Result<T, Error>;
32
33#[derive(Debug, PartialEq, Eq)]
34pub enum Error {
35    /// Column and value vector having different length
36    ColValNumMismatch { col_len: usize, val_len: usize },
37}
38
39impl std::error::Error for Error {}
40
41impl std::fmt::Display for Error {
42    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
43        match self {
44            Self::ColValNumMismatch { col_len, val_len } => write!(
45                f,
46                "Columns and values length mismatch: {col_len} != {val_len}"
47            ),
48        }
49    }
50}