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
use std::fmt;
use std::io::{Error as IOError};
pub enum DBError {
Unknown,
IO(IOError),
UnknownType(String),
AttributeMissing(String),
AttributeNullability(String),
AttributeType(String),
RowOutOfBounds,
Memory,
MemoryLimit,
}
impl DBError {
pub fn make_column_not_nullable(name: String) -> DBError {
DBError::AttributeNullability(name)
}
pub fn make_column_unknown_pos(pos: usize) -> DBError {
DBError::AttributeMissing(format!("(pos: {})", pos))
}
}
impl fmt::Display for DBError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
DBError::Unknown =>
write!(f, "Unknown Error"),
DBError::IO(ref e) =>
write!(f, "IO Error {}", e),
DBError::UnknownType(ref t) =>
write!(f, "Uknown/Enexpected Type {}", t),
DBError::AttributeMissing(ref attr) =>
write!(f, "Unknown Attribute {}", attr),
DBError::AttributeNullability(ref attr) =>
write!(f, "Attribute Not Nullable {}", attr),
DBError::AttributeType(ref attr) =>
write!(f, "Attribute Type Mismatch {}", attr),
DBError::RowOutOfBounds =>
write!(f, "Row out of bounds"),
DBError::Memory =>
write!(f, "Memory allocation failure"),
DBError::MemoryLimit =>
write!(f, "Memory allocation failure due to policy limit"),
}
}
}
impl fmt::Debug for DBError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}