1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use std::ops::Range;
use std::sync::Arc;
use std::{error, fmt, io, sync};
use arrow2::error::ArrowError;
use crate::storage::{Log, SeqNo};
#[derive(Debug, Clone)]
pub enum Error {
IO(Arc<io::Error>),
OutOfQuota(String),
String(String),
UnknownRegistration(String),
Noop(SeqNo, String),
RuntimeShutdown,
}
impl error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::IO(e) => fmt::Display::fmt(e, f),
Error::OutOfQuota(e) => f.write_str(e),
Error::String(e) => f.write_str(e),
Error::UnknownRegistration(id) => write!(f, "unknown registration: {}", id),
Error::Noop(_, e) => f.write_str(e),
Error::RuntimeShutdown => f.write_str("runtime shutdown"),
}
}
}
impl PartialEq for Error {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Error::String(s), Error::String(o)) => s == o,
(Error::OutOfQuota(s), Error::OutOfQuota(o)) => s == o,
(Error::RuntimeShutdown, Error::RuntimeShutdown) => true,
_ => false,
}
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
if let Some(28) = e.raw_os_error() {
return Error::OutOfQuota(e.to_string());
}
Error::IO(Arc::new(e))
}
}
impl From<String> for Error {
fn from(e: String) -> Self {
Error::String(e)
}
}
impl<'a> From<&'a str> for Error {
fn from(e: &'a str) -> Self {
Error::String(e.into())
}
}
impl From<ArrowError> for Error {
fn from(e: ArrowError) -> Self {
Error::String(e.to_string())
}
}
impl<T> From<sync::PoisonError<T>> for Error {
fn from(e: sync::PoisonError<T>) -> Self {
Error::String(format!("poison: {}", e))
}
}
#[derive(Debug)]
pub struct ErrorLog;
impl Log for ErrorLog {
fn write_sync(&mut self, _buf: Vec<u8>) -> Result<SeqNo, Error> {
Err(Error::from(
"ErrorLog method unexpectedly called, please report a bug: write_sync",
))
}
fn snapshot<F>(&self, _logic: F) -> Result<Range<SeqNo>, Error>
where
F: FnMut(SeqNo, &[u8]) -> Result<(), Error>,
{
Err(Error::from(
"ErrorLog method unexpectedly called, please report a bug: snapshot",
))
}
fn truncate(&mut self, _upper: SeqNo) -> Result<(), Error> {
Err(Error::from(
"ErrorLog method unexpectedly called, please report a bug: snapshot",
))
}
fn close(&mut self) -> Result<bool, Error> {
Ok(false)
}
}