1use std::sync::Arc;
13use std::{error, fmt, io, sync};
14
15use crate::location::{ExternalError, SeqNo};
16
17#[derive(Debug, Clone)]
19pub enum Error {
20 IO(Arc<io::Error>),
22 OutOfQuota(String),
24 String(String),
26 UnknownRegistration(String),
28 Noop(SeqNo, String),
34 RuntimeShutdown,
37}
38
39impl error::Error for Error {}
40
41impl fmt::Display for Error {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 match self {
44 Error::IO(e) => fmt::Display::fmt(e, f),
45 Error::OutOfQuota(e) => f.write_str(e),
46 Error::String(e) => f.write_str(e),
47 Error::UnknownRegistration(id) => write!(f, "unknown registration: {}", id),
48 Error::Noop(_, e) => f.write_str(e),
49 Error::RuntimeShutdown => f.write_str("runtime shutdown"),
50 }
51 }
52}
53
54impl PartialEq for Error {
56 fn eq(&self, other: &Self) -> bool {
57 match (self, other) {
58 (Error::String(s), Error::String(o)) => s == o,
59 (Error::OutOfQuota(s), Error::OutOfQuota(o)) => s == o,
60 (Error::UnknownRegistration(s), Error::UnknownRegistration(o)) => s == o,
61 (Error::RuntimeShutdown, Error::RuntimeShutdown) => true,
62 _ => false,
63 }
64 }
65}
66
67impl From<ExternalError> for Error {
68 fn from(e: ExternalError) -> Self {
69 Error::String(format!("{e:#}"))
71 }
72}
73
74impl From<io::Error> for Error {
75 fn from(e: io::Error) -> Self {
76 if let Some(28) = e.raw_os_error() {
78 return Error::OutOfQuota(e.to_string());
79 }
80 Error::IO(Arc::new(e))
81 }
82}
83
84impl From<String> for Error {
85 fn from(e: String) -> Self {
86 Error::String(e)
87 }
88}
89
90impl<'a> From<&'a str> for Error {
91 fn from(e: &'a str) -> Self {
92 Error::String(e.into())
93 }
94}
95
96impl From<parquet::errors::ParquetError> for Error {
97 fn from(e: parquet::errors::ParquetError) -> Self {
98 Error::String(e.to_string())
99 }
100}
101
102impl From<arrow::error::ArrowError> for Error {
103 fn from(e: arrow::error::ArrowError) -> Self {
104 Error::String(e.to_string())
105 }
106}
107
108impl<T> From<sync::PoisonError<T>> for Error {
109 fn from(e: sync::PoisonError<T>) -> Self {
110 Error::String(format!("poison: {}", e))
111 }
112}