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