use thiserror::Error;
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum AppendError {
#[error("ring buffer full")]
QueueFull,
#[error("append_batch called with an empty batch")]
EmptyBatch,
#[error("content size {size} exceeds maximum {max}")]
ContentTooLarge {
size: usize,
max: usize,
},
#[error("disk full")]
DiskFull,
#[error("I/O error: {0}")]
Io(String),
#[error("shutting down")]
ShuttingDown,
}
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum FlushError {
#[error("flush timed out")]
Timeout,
#[error("shutdown aborted")]
Aborted,
}
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum ReadError {
#[error("record {0} not found")]
NotFound(u64),
#[error("CRC mismatch at record {0}")]
CrcMismatch(u64),
#[error("I/O error: {0}")]
Io(String),
}
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum ShutdownError {
#[error("shutdown timed out")]
Timeout,
#[error("failed to join background threads")]
JoinError(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShutdownReport {
Clean,
PartialDurable,
TimedOut,
}
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum ConfigError {
#[error("ring_size must be a power of two >= 16, got {0}")]
InvalidRingSize(usize),
#[error("shards must be in [1, 256], got {0}")]
InvalidShardCount(usize),
#[error("segment_size must be >= 1MB, got {0}")]
SegmentTooSmall(u64),
#[error("max_content_size must be <= 64MB, got {0}")]
ContentTooLarge(usize),
#[error("index_stride must be >= 1")]
ZeroIndexStride,
#[cfg(feature = "hash-chain")]
#[error("hash-chain requires shards == 1, got shards = {shards}")]
HashChainRequiresSingleShard {
shards: usize,
},
}
#[derive(Error, Debug)]
pub enum OpenError {
#[error("invalid configuration: {0}")]
InvalidConfig(#[from] ConfigError),
#[error("recovery failed for shard {shard}: {reason}")]
Recovery {
shard: usize,
#[source]
reason: crate::recovery::RecoveryError,
},
#[error("failed to create segment manager: {0}")]
SegmentCreate(#[source] std::io::Error),
#[error("failed to spawn background thread: {0}")]
ThreadSpawn(#[source] std::io::Error),
}
#[derive(Error, Debug)]
pub enum TailerError {
#[error("tailer read error: {0}")]
Read(#[from] ReadError),
}