Skip to main content

mongreldb_core/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, MongrelError>;
4
5#[non_exhaustive]
6#[derive(Debug, Error)]
7pub enum MongrelError {
8    #[error("io error: {0}")]
9    Io(#[from] std::io::Error),
10    #[error("database at {path} is locked: {message}")]
11    DatabaseLocked {
12        path: std::path::PathBuf,
13        message: String,
14    },
15    #[error("database still has {strong_handles} shared handles")]
16    DatabaseBusy { strong_handles: usize },
17    #[error("database handle belongs to process {owner_pid}, not post-fork process {current_pid}; open after exec")]
18    ForkedProcess { owner_pid: u32, current_pid: u32 },
19    #[error("serialization error: {0}")]
20    Serialization(#[from] bincode::Error),
21    #[error("corrupt wal record at offset {offset}: {reason}")]
22    CorruptWal { offset: u64, reason: String },
23    #[error("torn wal write detected at offset {offset}")]
24    TornWrite { offset: u64 },
25    #[error("checksum mismatch for {context}: expected {expected}, got {actual}")]
26    ChecksumMismatch {
27        expected: u64,
28        actual: u64,
29        context: String,
30    },
31    #[error("magic mismatch in {what}: expected {expected:?}, got {got:?}")]
32    MagicMismatch {
33        what: &'static str,
34        expected: [u8; 8],
35        got: [u8; 8],
36    },
37    #[error("schema error: {0}")]
38    Schema(String),
39    #[error("column not found: {0}")]
40    ColumnNotFound(String),
41    #[error("encryption is required for this table but the `encryption` feature is disabled")]
42    EncryptionDisabled,
43    #[error("encryption error: {0}")]
44    Encryption(String),
45    #[error("decryption error: {0}")]
46    Decryption(String),
47    #[error("OS CSPRNG unavailable: {0}")]
48    EntropyUnavailable(String),
49    #[error("not found: {0}")]
50    NotFound(String),
51    #[error("invalid argument: {0}")]
52    InvalidArgument(String),
53    #[error("table is full: {0}")]
54    Full(String),
55    #[error("transaction conflict: {0}")]
56    Conflict(String),
57    #[error("trigger validation failed: {0}")]
58    TriggerValidation(String),
59    #[error("read-only replica: writes must be applied by ReplicationFollower")]
60    ReadOnlyReplica,
61    #[error("authentication required: this database has require_auth enabled; reopen with open_with_credentials / open_encrypted_with_credentials")]
62    AuthRequired,
63    #[error("authentication not required: this database does not have require_auth enabled; use the plain open/create constructors")]
64    AuthNotRequired,
65    #[error("invalid credentials for user {username:?}")]
66    InvalidCredentials { username: String },
67    #[error("permission denied: principal {principal:?} lacks {required}")]
68    PermissionDenied {
69        required: crate::auth::Permission,
70        principal: String,
71    },
72    #[error("execution deadline exceeded")]
73    DeadlineExceeded,
74    #[error("AI query work budget exceeded")]
75    WorkBudgetExceeded,
76    #[error(
77        "execution resource limit exceeded for {resource}: requested {requested}, limit {limit}"
78    )]
79    ResourceLimitExceeded {
80        resource: &'static str,
81        requested: usize,
82        limit: usize,
83    },
84    #[error("execution cancelled")]
85    Cancelled,
86    #[error("commit {epoch} is durable: {message}")]
87    DurableCommit { epoch: u64, message: String },
88    #[error("commit outcome at epoch {epoch} is unknown: {message}")]
89    CommitOutcomeUnknown { epoch: u64, message: String },
90    #[error("cursor stale: {0}")]
91    CursorStale(String),
92    #[error("cursor expired")]
93    CursorExpired,
94    #[error("{0}")]
95    Other(String),
96}