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
use super::ErrorPos;
use super::with_pos::WithPos;
use extern_mime;

error_chain! {
    foreign_links {
        IO(::std::io::Error);
        Fmt(::std::fmt::Error);
    }

    errors {
        Pos(message: String, pos: ErrorPos) {
            description("position error")
            display("{}", message)
        }

        DeclMerge(message: String, source: ErrorPos, target: ErrorPos) {
            description("declaration merge")
            display("{}", message)
        }

        FieldConflict(message: String, source: ErrorPos, target: ErrorPos) {
            description("field conflict")
            display("{}", message)
        }

        ExtendEnum(message: String, source: ErrorPos, enum_pos: ErrorPos) {
            description("extend enum")
            display("{}", message)
        }

        ReservedField(field_pos: ErrorPos, reserved_pos: ErrorPos) {
            description("field reserved")
            display("field reserved")
        }

        MatchConflict(source: ErrorPos, target: ErrorPos) {
            description("match conflict")
        }

        MimeFromStrError(error: extern_mime::FromStrError) {
            description("couldn't parse mime type")
            display("{:?}", error)
        }

        InvalidOrdinal {
        }

        /// Error thrown by Rc::get_mut
        RcGetMut {
        }

        RcTryUnwrap {
        }

        Overflow {
        }
    }
}

impl WithPos for Error {
    fn with_pos<E: Into<ErrorPos>>(self, pos: E) -> Self {
        use self::ErrorKind::*;

        match self.kind() {
            &Pos(..) => self,
            &DeclMerge(..) => self,
            &FieldConflict(..) => self,
            &ExtendEnum(..) => self,
            &ReservedField(..) => self,
            &MatchConflict(..) => self,
            _ => {
                let message = format!("{}", &self);
                self.chain_err(|| ErrorKind::Pos(message, pos.into()))
            }
        }
    }
}