Skip to main content

dactyl_db/
error.rs

1//! Errors returned by the Dactyl driver.
2
3use thiserror::Error;
4
5/// Coarse operational categories stable enough for callers to branch on.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum AdapterErrorKind {
8    Busy,
9    Locked,
10    Constraint,
11    Query,
12    ReadOnly,
13    Storage,
14    Transport,
15    Protocol,
16    Unknown,
17}
18
19/// The backend-neutral public error surface.
20#[derive(Debug, Error)]
21pub enum DactylError {
22    #[error("configuration error: {0}")]
23    Config(String),
24
25    #[error("adapter error ({kind:?}): {message}")]
26    Adapter {
27        kind: AdapterErrorKind,
28        message: String,
29    },
30
31    #[error("unsupported datastore operation: {0}")]
32    UnsupportedOperation(String),
33
34    #[error("column not found: {0}")]
35    ColumnNotFound(String),
36
37    #[error("conversion error: {0}")]
38    Conversion(String),
39}
40
41impl DactylError {
42    #[allow(dead_code)]
43    pub(crate) fn adapter(kind: AdapterErrorKind, message: impl Into<String>) -> Self {
44        Self::Adapter {
45            kind,
46            message: message.into(),
47        }
48    }
49}