pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("zstd seekable error: {0}")]
Zstd(#[from] zeekstd::Error),
#[error("invalid value: {0}")]
InvalidValue(&'static str),
#[error("unsupported type: {0}")]
UnsupportedType(String),
#[error("unsupported type combination: {0}")]
UnsupportedCombination(String),
#[error("type mismatch: expected {expected}, got {actual}")]
TypeMismatch {
expected: String,
actual: String,
},
#[error("value overflow: {0}")]
Overflow(&'static str),
#[error("internal error: {0}")]
Internal(&'static str),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_messages_are_human_friendly() {
let io_err = Error::Io(std::io::Error::other("boom"));
assert!(format!("{io_err}").contains("io error"));
let zstd_err = Error::Zstd(zeekstd::Error::from(std::io::Error::other("zstd")));
assert!(format!("{zstd_err}").contains("zstd seekable error"));
let invalid = Error::InvalidValue("oops");
assert!(format!("{invalid}").contains("oops"));
let unsupported = Error::UnsupportedType("Decimal(1)".into());
assert!(format!("{unsupported}").contains("unsupported type"));
let combo = Error::UnsupportedCombination("Nullable(Array(T))".into());
assert!(format!("{combo}").contains("unsupported type combination"));
let mismatch = Error::TypeMismatch {
expected: "UInt8".into(),
actual: "String".into(),
};
assert!(format!("{mismatch}").contains("expected"));
let overflow = Error::Overflow("too big");
assert!(format!("{overflow}").contains("too big"));
let internal = Error::Internal("bug");
assert!(format!("{internal}").contains("bug"));
}
}