use thiserror::Error;
#[derive(Debug, Error)]
pub enum IncrementalCheckpointError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Deserialization error: {0}")]
Deserialization(String),
#[error("WAL error: {0}")]
Wal(String),
#[error("Checkpoint not found: {0}")]
NotFound(String),
#[error("Checkpoint corruption: {0}")]
Corruption(String),
#[error("Recovery failed: {0}")]
Recovery(String),
#[error("Changelog buffer overflow at epoch {epoch}")]
BufferOverflow {
epoch: u64,
},
#[error("Invalid configuration: {0}")]
InvalidConfig(String),
#[error("Checkpoint already exists for epoch {0}")]
AlreadyExists(u64),
#[error("Epoch mismatch: expected {expected}, found {found}")]
EpochMismatch {
expected: u64,
found: u64,
},
#[error("CRC mismatch at offset {offset}: expected {expected:#x}, computed {computed:#x}")]
CrcMismatch {
offset: u64,
expected: u32,
computed: u32,
},
}
impl IncrementalCheckpointError {
#[must_use]
pub fn is_transient(&self) -> bool {
matches!(self, Self::Io(_) | Self::BufferOverflow { .. })
}
#[must_use]
pub fn is_corruption(&self) -> bool {
matches!(self, Self::Corruption(_) | Self::CrcMismatch { .. })
}
}