Skip to main content

oxisql_sqlite_compat/
error.rs

1//! Error types for the SQLite-compat (Limbo) backend.
2
3use oxisql_core::OxiSqlError;
4
5/// Errors produced by the `oxisql-sqlite-compat` backend.
6///
7/// These are always mapped to the corresponding [`OxiSqlError`] variant before
8/// they cross the [`Connection`][oxisql_core::Connection] trait boundary.
9/// Internal helpers and module tests use this type directly for richer
10/// context.
11#[derive(Debug, thiserror::Error)]
12pub enum SqliteCompatError {
13    /// A Limbo SQL execution or step error.
14    ///
15    /// The inner string is the `Display` representation of `limbo::Error`.
16    #[error("limbo execution error: {0}")]
17    Limbo(String),
18
19    /// A type-mapping failure (e.g. value out of range, unexpected variant).
20    #[error("type mapping error: {0}")]
21    TypeMap(String),
22
23    /// Connection setup / open failure.
24    #[error("connection error: {0}")]
25    Connection(String),
26
27    /// Attempted a nested `BEGIN` while already inside a transaction.
28    #[error("transaction already active — nested transactions are not supported")]
29    NestedTransaction,
30
31    /// A schema introspection query returned an unexpected result.
32    #[error("schema introspection error: {0}")]
33    Schema(String),
34
35    /// A general internal error that does not fit the above categories.
36    #[error("{0}")]
37    Other(String),
38}
39
40impl From<limbo::Error> for SqliteCompatError {
41    fn from(e: limbo::Error) -> Self {
42        SqliteCompatError::Limbo(e.to_string())
43    }
44}
45
46impl From<SqliteCompatError> for OxiSqlError {
47    fn from(e: SqliteCompatError) -> Self {
48        match e {
49            SqliteCompatError::Limbo(msg) => OxiSqlError::Execution(msg),
50            SqliteCompatError::TypeMap(msg) => OxiSqlError::Other(msg),
51            SqliteCompatError::Connection(msg) => OxiSqlError::Other(msg),
52            SqliteCompatError::NestedTransaction => {
53                OxiSqlError::Other("nested transactions are not supported".into())
54            }
55            SqliteCompatError::Schema(msg) => OxiSqlError::Other(msg),
56            SqliteCompatError::Other(msg) => OxiSqlError::Other(msg),
57        }
58    }
59}