Skip to main content

ave_core/helpers/db/
error.rs

1//! Database error types.
2//!
3
4use thiserror::Error;
5
6/// Errors that can occur during database operations.
7#[derive(Debug, Clone, Error)]
8pub enum DatabaseError {
9    /// Failed to acquire mutex lock on database connection.
10    #[error("failed to lock database connection")]
11    MutexLock,
12
13    /// Database pool or connection coordination failed.
14    #[error("database pool error: {0}")]
15    Pool(String),
16
17    /// Failed to open database connection.
18    #[error("failed to open database connection: {0}")]
19    ConnectionOpen(String),
20
21    /// Database migration failed.
22    #[error("migration failed: {0}")]
23    Migration(String),
24
25    /// Failed to create database directory.
26    #[error("failed to create database directory: {0}")]
27    DirectoryCreation(String),
28
29    /// SQL query execution failed.
30    #[error("query failed: {0}")]
31    Query(String),
32
33    /// Failed to serialize data to JSON.
34    #[error("JSON serialization failed: {0}")]
35    JsonSerialize(String),
36
37    /// Failed to deserialize data from JSON.
38    #[error("JSON deserialization failed: {0}")]
39    JsonDeserialize(String),
40
41    /// Integer conversion failed (e.g., u64 to i64).
42    #[error("integer conversion failed: {0}")]
43    IntegerConversion(String),
44
45    /// Subject not found in database.
46    #[error("subject not found: {0}")]
47    SubjectNotFound(String),
48
49    /// Governance not found in register projection.
50    #[error("governance not found: {0}")]
51    GovernanceNotFound(String),
52
53    /// Event not found in database.
54    #[error("event not found for subject {subject_id} at sn {sn}")]
55    EventNotFound { subject_id: String, sn: u64 },
56
57    /// No events found for subject.
58    #[error("no events found for subject: {0}")]
59    NoEvents(String),
60
61    /// Failed to parse date/time string.
62    #[error("date/time parse failed: {0}")]
63    DateTimeParse(String),
64
65    /// Invalid pagination cursor.
66    #[error("invalid pagination cursor: {0}")]
67    InvalidCursor(String),
68
69    /// Failed to execute SQLite work in a blocking task.
70    #[error("database blocking task failed: {0}")]
71    BlockingTask(String),
72}