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

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

    errors {
        Context {
            description("error")
            display("error")
        }

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

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

        InvalidOrdinal {
        }

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

        RcTryUnwrap {
        }
    }
}

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

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