Skip to main content

object_log/
error.rs

1use thiserror::Error;
2
3/// Errors returned by the object-log engine, storage adapters, and sequencer.
4#[derive(Debug, Error, Clone, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum ObjectLogError {
7    /// An object key was empty or contained a `..` path component or `\0`.
8    #[error("invalid object key: {0}")]
9    InvalidObjectKey(String),
10    /// The storage layer was unreachable or returned an I/O error.
11    #[error("storage unavailable: {0}")]
12    StorageUnavailable(String),
13    /// A `get_range` request named a byte range outside the object, or inverted.
14    #[error("byte range out of bounds: {0}")]
15    RangeOutOfBounds(String),
16    /// The index referenced an object that is no longer present in storage.
17    #[error("missing object: {0}")]
18    MissingObject(String),
19    /// A produce batch was malformed (e.g. empty, or below the configured floor).
20    #[error("invalid produce batch: {0}")]
21    InvalidBatch(String),
22    /// The sequencer rejected or failed to process a commit/lookup.
23    #[error("sequencer error: {0}")]
24    Sequencer(String),
25
26    /// The partition's fence epoch moved past the write's epoch, so the write was
27    /// not committed. Retrying at the same epoch cannot succeed.
28    ///
29    /// Produced by a sequencer's [`rejection_error`](crate::Sequencer::rejection_error)
30    /// (for example [`ManifestSequencer`](crate::ManifestSequencer)); the engine
31    /// never constructs it.
32    #[error(
33        "partition {partition} is fenced at epoch {current}; the write at epoch {epoch} was not committed"
34    )]
35    Fenced {
36        /// Partition whose fence rejected the write.
37        partition: String,
38        /// Epoch the write was produced at.
39        epoch: u64,
40        /// Fence epoch the partition's index holds.
41        current: u64,
42    },
43    /// A conditional batch was definitely not indexed at its expected log head.
44    #[error("conditional log head moved from {expected} to {current}")]
45    HeadRejected {
46        /// Original required next offset.
47        expected: i64,
48        /// Authoritative next offset that did not match.
49        current: i64,
50    },
51    /// Durable-ops budget admission failed (`BudgetMode::FailClosed` or timed out).
52    #[error("durable-ops budget exceeded: {0}")]
53    BudgetExceeded(String),
54    /// An authenticated native payload exceeds the caller's read limit.
55    #[error("native payload length {actual} exceeds read limit {limit}")]
56    ReadLimitExceeded {
57        /// Authenticated payload length, before data hydration.
58        actual: usize,
59        /// Caller-supplied maximum payload length.
60        limit: usize,
61    },
62    /// Invalid engine or budget configuration.
63    #[error("invalid configuration: {0}")]
64    InvalidConfig(String),
65}
66
67impl From<std::io::Error> for ObjectLogError {
68    fn from(value: std::io::Error) -> Self {
69        Self::StorageUnavailable(value.to_string())
70    }
71}