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("serialization error: {0}")]
11    Serialization(#[from] bincode::Error),
12    #[error("corrupt wal record at offset {offset}: {reason}")]
13    CorruptWal { offset: u64, reason: String },
14    #[error("torn wal write detected at offset {offset}")]
15    TornWrite { offset: u64 },
16    #[error("checksum mismatch for {context}: expected {expected}, got {actual}")]
17    ChecksumMismatch {
18        expected: u64,
19        actual: u64,
20        context: String,
21    },
22    #[error("magic mismatch in {what}: expected {expected:?}, got {got:?}")]
23    MagicMismatch {
24        what: &'static str,
25        expected: [u8; 8],
26        got: [u8; 8],
27    },
28    #[error("schema error: {0}")]
29    Schema(String),
30    #[error("column not found: {0}")]
31    ColumnNotFound(String),
32    #[error("encryption is required for this table but the `encryption` feature is disabled")]
33    EncryptionDisabled,
34    #[error("encryption error: {0}")]
35    Encryption(String),
36    #[error("decryption error: {0}")]
37    Decryption(String),
38    #[error("not found: {0}")]
39    NotFound(String),
40    #[error("invalid argument: {0}")]
41    InvalidArgument(String),
42    #[error("table is full: {0}")]
43    Full(String),
44    #[error("transaction conflict: {0}")]
45    Conflict(String),
46    #[error("authentication required: this database has require_auth enabled; reopen with open_with_credentials / open_encrypted_with_credentials")]
47    AuthRequired,
48    #[error("authentication not required: this database does not have require_auth enabled; use the plain open/create constructors")]
49    AuthNotRequired,
50    #[error("invalid credentials for user {username:?}")]
51    InvalidCredentials { username: String },
52    #[error("permission denied: principal {principal:?} lacks {required}")]
53    PermissionDenied {
54        required: crate::auth::Permission,
55        principal: String,
56    },
57    #[error("{0}")]
58    Other(String),
59}