Skip to main content

drizzle_core/
error.rs

1//! Error types for drizzle-core
2
3use thiserror::Error;
4
5/// Core error type for drizzle operations
6#[derive(Debug, Error)]
7pub enum DrizzleError {
8    /// Error executing a query
9    #[error("Execution error: {0}")]
10    ExecutionError(compact_str::CompactString),
11
12    /// Error preparing a statement
13    #[error("Prepare error: {0}")]
14    PrepareError(compact_str::CompactString),
15
16    /// No rows returned when at least one was expected
17    #[error("No rows found")]
18    NotFound,
19
20    /// Error with transaction
21    #[error("Transaction error: {0}")]
22    TransactionError(compact_str::CompactString),
23
24    /// Error mapping data
25    #[error("Mapping error: {0}")]
26    Mapping(compact_str::CompactString),
27
28    /// Error in statement
29    #[error("Statement error: {0}")]
30    Statement(compact_str::CompactString),
31
32    /// Error in query
33    #[error("Query error: {0}")]
34    Query(compact_str::CompactString),
35
36    /// Error converting parameters
37    #[error("Parameter conversion error: {0}")]
38    ParameterError(compact_str::CompactString),
39
40    /// Integer conversion error
41    #[error("Integer conversion error: {0}")]
42    TryFromInt(#[from] core::num::TryFromIntError),
43
44    /// Parse int error
45    #[error("Parse int error: {0}")]
46    ParseInt(#[from] core::num::ParseIntError),
47
48    /// Parse float error
49    #[error("Parse float error: {0}")]
50    ParseFloat(#[from] core::num::ParseFloatError),
51
52    /// Parse bool error
53    #[error("Parse bool error: {0}")]
54    ParseBool(#[from] core::str::ParseBoolError),
55
56    /// Type conversion error
57    #[error("Type conversion error: {0}")]
58    ConversionError(compact_str::CompactString),
59
60    /// Schema error (e.g. cycle in table dependencies)
61    #[error("Schema error: {0}")]
62    Schema(compact_str::CompactString),
63
64    /// Generic error
65    #[error("Database error: {0}")]
66    Other(compact_str::CompactString),
67
68    /// Rusqlite specific errors
69    #[cfg(feature = "rusqlite")]
70    #[error("Rusqlite error: {0}")]
71    Rusqlite(#[from] rusqlite::Error),
72
73    /// Turso specific errors
74    #[cfg(feature = "turso")]
75    #[error("Turso error: {0}")]
76    Turso(#[from] turso::Error),
77
78    /// `LibSQL` specific errors
79    #[cfg(feature = "libsql")]
80    #[error("LibSQL error: {0}")]
81    LibSQL(#[from] libsql::Error),
82
83    /// Postgres specific errors
84    #[cfg(feature = "tokio-postgres")]
85    #[error("Postgres error: {0}")]
86    Postgres(#[from] tokio_postgres::Error),
87
88    #[cfg(all(feature = "postgres-sync", not(feature = "tokio-postgres")))]
89    #[error("Postgres error: {0}")]
90    Postgres(#[from] postgres::Error),
91
92    /// UUID parsing error
93    #[cfg(feature = "uuid")]
94    #[error("UUID error: {0}")]
95    UuidError(#[from] uuid::Error),
96
97    /// JSON serialization/deserialization error
98    #[cfg(feature = "serde")]
99    #[error("JSON error: {0}")]
100    JsonError(#[from] serde_json::Error),
101
102    /// Infallible conversion error (should never happen)
103    #[error("Infallible conversion error")]
104    Infallible(#[from] core::convert::Infallible),
105}
106
107/// Result type for database operations
108pub type Result<T> = core::result::Result<T, DrizzleError>;