1use std::fmt;
2use std::io;
3use std::error::Error;
4
5use Pos;
6
7
8quick_error! {
9 #[derive(Debug)]
11 pub enum DataError {
12 AttrUnsupported(typename: &'static str) {
14 description("object doesn't support getting attribute `a.b`")
15 display("object {} doesn't support getting attribute", typename)
16 }
17 AttrNotFound {
19 description("object doesn't have such attibute")
20 }
21 IndexUnsupported(typename: &'static str) {
23 description("object doesn't support subscription `a[b]`")
24 display("object {} doesn't support subscription", typename)
25 }
26 StrKeyUnsupported(typename: &'static str) {
28 description("can't be stringified for subsciption `a[b]`")
29 display("object {} can't be stringified to be used as key", typename)
30 }
31 IntKeyUnsupported(typename: &'static str) {
33 description("can't used as integer key for subscription")
34 display("object {} can't be a key for subscription", typename)
35 }
36 IndexNotFound {
38 description("object doesn't have value at specified index")
39 }
40 OutputUnsupported(typename: &'static str) {
42 description("can't print object of this type")
43 display("can't print object of type {}", typename)
44 }
45 OutputError(typename: &'static str) {
47 description("error when formatting value")
48 display("error when formatting value of type {}", typename)
49 }
50 UnknownValidator(name: String) {
52 description("unknown validator")
53 display("validator {:?} is not defined", name)
54 }
55 RegexValidationError(data: String, regex: String) {
57 description("validation error")
58 display("output {:?} should match regex {:?}", data, regex)
59 }
60 BoolUnsupported(typename: &'static str) {
62 description("can't treat object of this type as bool")
63 display("can't treat object of type {} as bool", typename)
64 }
65 NumberUnsupported(typename: &'static str) {
67 description("can't treat object of this type as number")
68 display("can't treat object of type {} as number", typename)
69 }
70 ComparisonUnsupported(typename: &'static str) {
72 description("can't compare objects of this type")
73 display("can't compare objects of type {}", typename)
74 }
75 IterationUnsupported(typename: &'static str) {
77 description("can't iterate over the object")
78 display("can't iterate over the object of type {}", typename)
79 }
80 PairIterationUnsupported(typename: &'static str) {
82 description("can't iterate over the object by pairs")
83 display("can't iterate over the object by pairs of type {}",
84 typename)
85 }
86 VariableNotFound(name: String) {
88 description("variable or attribute not found")
89 display("variable or attribute {:?} not found", name)
90 }
91 Incomparable(left_type: &'static str, right_type: &'static str) {
93 description("two types can't be compared")
94 display("Can't compare object of type {:?} to {:?}",
95 left_type, right_type)
96 }
97 Custom(err: Box<Error>) {
99 description(err.description())
100 display("{}", err)
101 cause(&**err)
102 }
103 #[doc(hidden)]
104 __Nonexhaustive
105 }
106}
107
108
109quick_error! {
110 #[derive(Debug)]
112 pub enum RenderError {
113 Io(err: io::Error) {
115 display("I/O error: {}", err)
116 description("I/O error")
117 from()
118 }
119 Fmt(err: fmt::Error) {
123 description("error formatting value")
124 from()
125 }
126 Data(errs: Vec<(Pos, DataError)>) {
132 display("data error: {}", errs.iter()
133 .map(|&(p, ref e)| format!("{}: {}", p, e))
134 .collect::<Vec<_>>().join("\n "))
135 description("data error")
136 }
137 }
138}