Skip to main content

salamander/
error.rs

1//! Error type for the crate: one enum with a `thiserror` derive.
2
3/// The error type returned by every fallible operation in this crate.
4///
5/// Each variant's `Display` output (from the `thiserror` `#[error("…")]`
6/// attribute) documents what it means; callers that need to branch on a
7/// failure should match on the variant rather than parse the message,
8/// which is not a stable API.
9#[derive(Debug, thiserror::Error)]
10#[allow(missing_docs)] // Each variant is documented by its #[error("…")] message.
11pub enum SalamanderError {
12    #[error("invalid argument: {0}")]
13    InvalidArgument(String),
14
15    #[error("io: {0}")]
16    Io(#[from] std::io::Error),
17
18    #[error("corrupt record at offset {offset}: {reason}")]
19    Corrupt { offset: u64, reason: String },
20
21    #[error("offset {0} beyond head")]
22    OffsetBeyondHead(u64),
23
24    #[error("manifest error: {0}")]
25    Manifest(String),
26
27    #[error(
28        "unsupported payload format version {found}: this build supports {supported}. \
29         The data dir was written by a newer SalamanderDB; upgrade to read it."
30    )]
31    UnsupportedFormat { found: u32, supported: u32 },
32
33    #[error("unsupported storage format version {found}: this build writes version {supported}; migrate the source directory offline")]
34    UnsupportedStorageFormat { found: u32, supported: u32 },
35
36    #[error("invalid segment file name: {0}")]
37    InvalidSegmentName(String),
38
39    #[error("namespace {0} already exists")]
40    NamespaceExists(String),
41
42    #[error("data dir is locked by another process: {0}")]
43    Locked(String),
44
45    #[error("serialization error: {0}")]
46    Serialization(String),
47
48    #[error("invalid format: {0}")]
49    InvalidFormat(String),
50
51    #[error("codec error: {0}")]
52    Codec(String),
53
54    #[error("resource limit exceeded: {resource} is {actual}, maximum is {maximum}")]
55    ResourceLimit {
56        resource: &'static str,
57        actual: u64,
58        maximum: u64,
59    },
60
61    #[error("migration error: {0}")]
62    Migration(String),
63
64    #[error("migration is incomplete for {0}; resume it with the migration command")]
65    MigrationIncomplete(String),
66
67    #[error("stream revision conflict: expected {expected}, actual {actual}")]
68    RevisionConflict { expected: String, actual: String },
69
70    #[error("event ID already exists with different content")]
71    EventIdConflict,
72
73    #[error("idempotency key already exists with different content")]
74    IdempotencyConflict,
75
76    #[error("batch ID already exists with different content")]
77    BatchIdConflict,
78
79    #[error("branch not found: {0}")]
80    BranchNotFound(String),
81
82    #[error("branch already exists: {0}")]
83    BranchExists(String),
84
85    #[error("branch is archived: {0}")]
86    BranchArchived(String),
87
88    #[error("invalid branch ancestry: {0}")]
89    InvalidBranchAncestry(String),
90
91    #[error("position {0} is not a committed batch boundary")]
92    NotBatchBoundary(u64),
93}
94
95/// Shorthand for a `Result` whose error is [`SalamanderError`].
96pub type Result<T> = std::result::Result<T, SalamanderError>;