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("unsupported {component} storage version {found}: this build supports version {supported} only; recreate the database or export data using the engine version that created it")]
38    UnsupportedStorageVersion {
39        component: &'static str,
40        found: u16,
41        supported: u16,
42    },
43    #[error("schema error: {0}")]
44    Schema(String),
45    #[error("column not found: {0}")]
46    ColumnNotFound(String),
47    #[error("encryption is required for this table but the `encryption` feature is disabled")]
48    EncryptionDisabled,
49    #[error("encryption error: {0}")]
50    Encryption(String),
51    #[error("decryption error: {0}")]
52    Decryption(String),
53    #[error("OS CSPRNG unavailable: {0}")]
54    EntropyUnavailable(String),
55    #[error("not found: {0}")]
56    NotFound(String),
57    #[error("invalid argument: {0}")]
58    InvalidArgument(String),
59    #[error("table is full: {0}")]
60    Full(String),
61    #[error("transaction conflict: {0}")]
62    Conflict(String),
63    #[error("trigger validation failed: {0}")]
64    TriggerValidation(String),
65    #[error("read-only replica: writes must be applied by ReplicationFollower")]
66    ReadOnlyReplica,
67    #[error("authentication required: this database has require_auth enabled; reopen with open_with_credentials / open_encrypted_with_credentials")]
68    AuthRequired,
69    #[error("authentication not required: this database does not have require_auth enabled; use the plain open/create constructors")]
70    AuthNotRequired,
71    #[error("invalid credentials for user {username:?}")]
72    InvalidCredentials { username: String },
73    #[error("permission denied: principal {principal:?} lacks {required}")]
74    PermissionDenied {
75        required: crate::auth::Permission,
76        principal: String,
77    },
78    #[error("execution deadline exceeded")]
79    DeadlineExceeded,
80    #[error("AI query work budget exceeded")]
81    WorkBudgetExceeded,
82    #[error(
83        "execution resource limit exceeded for {resource}: requested {requested}, limit {limit}"
84    )]
85    ResourceLimitExceeded {
86        resource: &'static str,
87        requested: usize,
88        limit: usize,
89    },
90    #[error("execution cancelled")]
91    Cancelled,
92    #[error("commit {epoch} is durable: {message}")]
93    DurableCommit { epoch: u64, message: String },
94    #[error("commit outcome at epoch {epoch} is unknown: {message}")]
95    CommitOutcomeUnknown { epoch: u64, message: String },
96    #[error("cursor stale: {0}")]
97    CursorStale(String),
98    #[error("cursor expired")]
99    CursorExpired,
100    #[error("{0}")]
101    Other(String),
102}