1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[non_exhaustive]
7pub enum Feature {
8 Snappy,
10 Brotli,
12 Gzip,
14 Lz4,
16 Zstd,
18}
19
20#[derive(Debug, Clone)]
22#[non_exhaustive]
23pub enum Error {
24 OutOfSpec(String),
26 FeatureNotActive(Feature, String),
28 FeatureNotSupported(String),
30 InvalidParameter(String),
32 WouldOverAllocate,
34}
35
36impl Error {
37 pub(crate) fn oos<I: Into<String>>(message: I) -> Self {
38 Self::OutOfSpec(message.into())
39 }
40}
41
42impl std::error::Error for Error {}
43
44impl std::fmt::Display for Error {
45 fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
46 match self {
47 Error::OutOfSpec(message) => {
48 write!(fmt, "File out of specification: {}", message)
49 }
50 Error::FeatureNotActive(feature, reason) => {
51 write!(
52 fmt,
53 "The feature \"{:?}\" needs to be active to {}",
54 feature, reason
55 )
56 }
57 Error::FeatureNotSupported(reason) => {
58 write!(fmt, "Not yet supported: {}", reason)
59 }
60 Error::InvalidParameter(message) => {
61 write!(fmt, "Invalid parameter: {}", message)
62 }
63 Error::WouldOverAllocate => {
64 write!(fmt, "Operation would exceed memory use threshold")
65 }
66 }
67 }
68}
69
70#[cfg(feature = "snappy")]
71impl From<snap::Error> for Error {
72 fn from(e: snap::Error) -> Error {
73 Error::OutOfSpec(format!("underlying snap error: {}", e))
74 }
75}
76
77#[cfg(feature = "lz4_flex")]
78impl From<lz4_flex::block::DecompressError> for Error {
79 fn from(e: lz4_flex::block::DecompressError) -> Error {
80 Error::OutOfSpec(format!("underlying lz4_flex error: {}", e))
81 }
82}
83
84#[cfg(feature = "lz4_flex")]
85impl From<lz4_flex::block::CompressError> for Error {
86 fn from(e: lz4_flex::block::CompressError) -> Error {
87 Error::OutOfSpec(format!("underlying lz4_flex error: {}", e))
88 }
89}
90
91impl From<parquet_format_safe::thrift::Error> for Error {
92 fn from(e: parquet_format_safe::thrift::Error) -> Error {
93 Error::OutOfSpec(format!("Invalid thrift: {}", e))
94 }
95}
96
97impl From<std::io::Error> for Error {
98 fn from(e: std::io::Error) -> Error {
99 Error::OutOfSpec(format!("underlying IO error: {}", e))
100 }
101}
102
103impl From<std::collections::TryReserveError> for Error {
104 fn from(e: std::collections::TryReserveError) -> Error {
105 Error::OutOfSpec(format!("OOM: {}", e))
106 }
107}
108
109impl From<std::num::TryFromIntError> for Error {
110 fn from(e: std::num::TryFromIntError) -> Error {
111 Error::OutOfSpec(format!("Number must be zero or positive: {}", e))
112 }
113}
114
115impl From<std::array::TryFromSliceError> for Error {
116 fn from(e: std::array::TryFromSliceError) -> Error {
117 Error::OutOfSpec(format!("Can't deserialize to parquet native type: {}", e))
118 }
119}
120
121pub type Result<T> = std::result::Result<T, Error>;