1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum Error {
5 Schema(String),
6 ColumnNotFound(String),
7 TypeMismatch { expected: String, actual: String },
8 InvalidSelection(String),
9 InvalidArgument(String),
10 Unsupported(String),
11 NotImplemented(&'static str),
12 Io(String),
13 Parse(String),
14}
15
16impl fmt::Display for Error {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 match self {
19 Self::Schema(message) => write!(f, "schema error: {message}"),
20 Self::ColumnNotFound(name) => write!(f, "column not found: {name}"),
21 Self::TypeMismatch { expected, actual } => {
22 write!(f, "type mismatch: expected {expected}, got {actual}")
23 }
24 Self::InvalidSelection(message) => write!(f, "invalid selection: {message}"),
25 Self::InvalidArgument(message) => write!(f, "invalid argument: {message}"),
26 Self::Unsupported(message) => write!(f, "unsupported: {message}"),
27 Self::NotImplemented(message) => write!(f, "not implemented: {message}"),
28 Self::Io(message) => write!(f, "io error: {message}"),
29 Self::Parse(message) => write!(f, "parse error: {message}"),
30 }
31 }
32}
33
34impl std::error::Error for Error {}
35
36impl From<std::io::Error> for Error {
37 fn from(value: std::io::Error) -> Self {
38 Self::Io(value.to_string())
39 }
40}
41
42impl From<csv::Error> for Error {
43 fn from(value: csv::Error) -> Self {
44 Self::Io(value.to_string())
45 }
46}
47
48pub type Result<T> = std::result::Result<T, Error>;