1use std::fmt;
4
5#[derive(Debug)]
7pub enum OxiSqlError {
8 Parse(String),
10 Execution(String),
12 NotConnected,
14 TypeMismatch {
16 expected: &'static str,
18 got: &'static str,
20 },
21 ConstraintViolation(String),
23 Timeout(String),
25 ConnectionPool(String),
27 Migration(String),
29 UnsupportedUri(String),
31 Params(String),
33 Other(String),
35}
36
37impl fmt::Display for OxiSqlError {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 match self {
40 OxiSqlError::Parse(s) => write!(f, "SQL parse error: {s}"),
41 OxiSqlError::Execution(s) => write!(f, "execution error: {s}"),
42 OxiSqlError::NotConnected => write!(f, "not connected"),
43 OxiSqlError::TypeMismatch { expected, got } => {
44 write!(f, "type mismatch: expected {expected}, got {got}")
45 }
46 OxiSqlError::ConstraintViolation(s) => {
47 write!(f, "constraint violation: {s}")
48 }
49 OxiSqlError::Timeout(s) => write!(f, "timeout: {s}"),
50 OxiSqlError::ConnectionPool(s) => write!(f, "connection pool error: {s}"),
51 OxiSqlError::Migration(s) => write!(f, "migration error: {s}"),
52 OxiSqlError::UnsupportedUri(s) => write!(f, "unsupported URI or feature: {s}"),
53 OxiSqlError::Params(s) => write!(f, "parameter binding error: {s}"),
54 OxiSqlError::Other(s) => write!(f, "error: {s}"),
55 }
56 }
57}
58
59impl std::error::Error for OxiSqlError {}