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(
25        "position {requested} is unavailable: retained history starts at {floor}, head is {head}"
26    )]
27    PositionUnavailable {
28        requested: u64,
29        floor: u64,
30        head: u64,
31        bootstrap_available: bool,
32    },
33
34    #[error("manifest error: {0}")]
35    Manifest(String),
36
37    #[error(
38        "unsupported payload format version {found}: this build supports {supported}. \
39         The data dir was written by a newer SalamanderDB; upgrade to read it."
40    )]
41    UnsupportedFormat { found: u32, supported: u32 },
42
43    #[error("unsupported storage format version {found}: this build writes version {supported}; migrate the source directory offline")]
44    UnsupportedStorageFormat { found: u32, supported: u32 },
45
46    #[error("invalid segment file name: {0}")]
47    InvalidSegmentName(String),
48
49    #[error("namespace {0} already exists")]
50    NamespaceExists(String),
51
52    #[error("data dir is locked by another process: {0}")]
53    Locked(String),
54
55    #[error("serialization error: {0}")]
56    Serialization(String),
57
58    #[error("invalid format: {0}")]
59    InvalidFormat(String),
60
61    #[error("codec error: {0}")]
62    Codec(String),
63
64    #[error("resource limit exceeded: {resource} is {actual}, maximum is {maximum}")]
65    ResourceLimit {
66        resource: &'static str,
67        actual: u64,
68        maximum: u64,
69    },
70
71    #[error("migration error: {0}")]
72    Migration(String),
73
74    #[error("migration is incomplete for {0}; resume it with the migration command")]
75    MigrationIncomplete(String),
76
77    #[error("stream revision conflict: expected {expected}, actual {actual}")]
78    RevisionConflict { expected: String, actual: String },
79
80    #[error("event ID already exists with different content")]
81    EventIdConflict,
82
83    #[error("idempotency key already exists with different content")]
84    IdempotencyConflict,
85
86    #[error("batch ID already exists with different content")]
87    BatchIdConflict,
88
89    #[error("branch not found: {0}")]
90    BranchNotFound(String),
91
92    #[error("branch already exists: {0}")]
93    BranchExists(String),
94
95    #[error("branch is archived: {0}")]
96    BranchArchived(String),
97
98    #[error("invalid branch ancestry: {0}")]
99    InvalidBranchAncestry(String),
100
101    #[error("position {0} is not a committed batch boundary")]
102    NotBatchBoundary(u64),
103}
104
105/// Shorthand for a `Result` whose error is [`SalamanderError`].
106pub type Result<T> = std::result::Result<T, SalamanderError>;