#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Feature {
Snappy,
Brotli,
Gzip,
Lz4,
Zstd,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum Error {
OutOfSpec(String),
FeatureNotActive(Feature, String),
FeatureNotSupported(String),
InvalidParameter(String),
WouldOverAllocate,
}
impl Error {
pub(crate) fn oos<I: Into<String>>(message: I) -> Self {
Self::OutOfSpec(message.into())
}
}
impl std::error::Error for Error {}
impl std::fmt::Display for Error {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::OutOfSpec(message) => {
write!(fmt, "File out of specification: {}", message)
}
Error::FeatureNotActive(feature, reason) => {
write!(
fmt,
"The feature \"{:?}\" needs to be active to {}",
feature, reason
)
}
Error::FeatureNotSupported(reason) => {
write!(fmt, "Not yet supported: {}", reason)
}
Error::InvalidParameter(message) => {
write!(fmt, "Invalid parameter: {}", message)
}
Error::WouldOverAllocate => {
write!(fmt, "Operation would exceed memory use threshold")
}
}
}
}
#[cfg(feature = "snappy")]
impl From<snap::Error> for Error {
fn from(e: snap::Error) -> Error {
Error::OutOfSpec(format!("underlying snap error: {}", e))
}
}
#[cfg(feature = "lz4_flex")]
impl From<lz4_flex::block::DecompressError> for Error {
fn from(e: lz4_flex::block::DecompressError) -> Error {
Error::OutOfSpec(format!("underlying lz4_flex error: {}", e))
}
}
#[cfg(feature = "lz4_flex")]
impl From<lz4_flex::block::CompressError> for Error {
fn from(e: lz4_flex::block::CompressError) -> Error {
Error::OutOfSpec(format!("underlying lz4_flex error: {}", e))
}
}
impl From<parquet_format_safe::thrift::Error> for Error {
fn from(e: parquet_format_safe::thrift::Error) -> Error {
Error::OutOfSpec(format!("Invalid thrift: {}", e))
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Error {
Error::OutOfSpec(format!("underlying IO error: {}", e))
}
}
impl From<std::collections::TryReserveError> for Error {
fn from(e: std::collections::TryReserveError) -> Error {
Error::OutOfSpec(format!("OOM: {}", e))
}
}
impl From<std::num::TryFromIntError> for Error {
fn from(e: std::num::TryFromIntError) -> Error {
Error::OutOfSpec(format!("Number must be zero or positive: {}", e))
}
}
impl From<std::array::TryFromSliceError> for Error {
fn from(e: std::array::TryFromSliceError) -> Error {
Error::OutOfSpec(format!("Can't deserialize to parquet native type: {}", e))
}
}
pub type Result<T> = std::result::Result<T, Error>;