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
#![allow(missing_docs)]
use parse::error::ParseError;
use std::error::Error;
use std::fmt;
use types::Type;
#[derive(Debug, PartialEq, Eq)]
pub enum OverError {
ArrOutOfBounds(usize),
ArrTypeMismatch(Type, Type),
CircularParentReferences,
FieldNotFound(String),
NoParentFound,
ParseError(String),
TupOutOfBounds(usize),
TypeMismatch(Type),
}
impl fmt::Display for OverError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::OverError::*;
match *self {
ArrOutOfBounds(ref index) => write!(f, "Arr index out of bounds: {}", index),
ArrTypeMismatch(ref found, ref expected) => {
write!(
f,
"Arr inner types do not match: found {}, expected {}",
found,
expected
)
}
CircularParentReferences => {
write!(f, "Circular references among parents are not allowed")
}
FieldNotFound(ref field) => write!(f, "Field not found: {}", field),
NoParentFound => write!(f, "No parent found for this obj"),
ParseError(ref error) => write!(f, "{}", error),
TupOutOfBounds(ref index) => write!(f, "Tup index out of bounds: {}", index),
TypeMismatch(ref found) => write!(f, "Type mismatch: found {}", found),
}
}
}
impl Error for OverError {
fn description(&self) -> &str {
use self::OverError::*;
match *self {
ArrOutOfBounds(_) => "Arr index out of bounds",
ArrTypeMismatch(_, _) => "Arr inner types do not match",
CircularParentReferences => "Circular references among parents are not allowed",
FieldNotFound(_) => "Field not found",
NoParentFound => "No parent found for this obj",
ParseError(ref error) => error,
TupOutOfBounds(_) => "Tup index out of bounds",
TypeMismatch(_) => "Type mismatch",
}
}
}
impl From<ParseError> for OverError {
fn from(e: ParseError) -> Self {
OverError::ParseError(format!("{}", e))
}
}