use thiserror::Error;
use crate::Error as CoreError;
pub type Result<T> = std::result::Result<T, ColumnarError>;
#[derive(Debug, Error)]
pub enum ColumnarError {
#[error("checksum mismatch")]
ChecksumMismatch,
#[error("unsupported format version: found={found}, expected={expected}")]
UnsupportedFormatVersion {
found: u16,
expected: u16,
},
#[error("unsupported compression: {algorithm}")]
UnsupportedCompression {
algorithm: String,
},
#[error("memory limit exceeded: limit={limit}, requested={requested}")]
MemoryLimitExceeded {
limit: usize,
requested: usize,
},
#[error("invalid format: {0}")]
InvalidFormat(String),
#[error("not found")]
NotFound,
#[error("transaction conflict")]
TxnConflict,
#[error("row group too large: size={size}, max={max}")]
RowGroupTooLarge {
size: u64,
max: u64,
},
#[error("not in in-memory mode")]
NotInMemoryMode,
#[error("table not found: {table}")]
TableNotFound {
table: String,
},
#[error("corrupted segment: {reason}")]
CorruptedSegment {
reason: String,
},
#[error("encoding error: {reason}")]
EncodingError {
reason: String,
},
#[error("io error: {0}")]
Io(#[from] std::io::Error),
}
impl From<CoreError> for ColumnarError {
fn from(err: CoreError) -> Self {
match err {
CoreError::ChecksumMismatch => ColumnarError::ChecksumMismatch,
CoreError::InvalidFormat(reason) => ColumnarError::InvalidFormat(reason),
CoreError::CorruptedSegment { segment_id, reason } => ColumnarError::CorruptedSegment {
reason: format!("segment {segment_id}: {reason}"),
},
CoreError::MemoryLimitExceeded { limit, requested } => {
ColumnarError::MemoryLimitExceeded { limit, requested }
}
CoreError::TxnConflict => ColumnarError::TxnConflict,
CoreError::NotFound => ColumnarError::NotFound,
CoreError::Io(e) => ColumnarError::Io(e),
other => ColumnarError::EncodingError {
reason: other.to_string(),
},
}
}
}