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 79 80 81 82 83 84
use core::{errors as core, ErrorPos, Pos, Reporter, RpType, WithPos}; use parser::errors as parser; use path_parser::errors as path_parser; use repository::errors as repository; use serde_json as json; error_chain! { links { Parser(parser::Error, parser::ErrorKind); PathParser(path_parser::Error, path_parser::ErrorKind); Core(core::Error, core::ErrorKind); Repository(repository::Error, repository::ErrorKind); } foreign_links { Io(::std::io::Error); Fmt(::std::fmt::Error); Json(json::Error); BorrowMutError(::std::cell::BorrowMutError); BorrowError(::std::cell::BorrowError); } errors { Pos(message: String, pos: ErrorPos) { description("position error") display("{}", message) } Errors(errors: Vec<Error>) { description("errors") display("encountered {} error(s)", errors.len()) } MissingOutput { description("missing output directory, use --out or the `output` key in the manifest") } MissingPrefix(prefix: String) { description("missing prefix") display("missing prefix: {}", prefix) } MissingTypeImpl(ty: RpType, suggestion: &'static str) { description("missing type implementation") display("missing implementation for type `{}`, {}", ty, suggestion) } } } impl Error { pub fn pos(message: String, pos: ErrorPos) -> Error { ErrorKind::Pos(message, pos).into() } } impl WithPos for Error { fn with_pos<E: Into<ErrorPos>>(self, pos: E) -> Self { use self::ErrorKind::*; match self.kind() { &Pos(..) => self, &Errors(..) => self, &Core(..) => self, &Repository(..) => self, _ => { let message = format!("{}", self); self.chain_err(|| ErrorKind::Pos(message, pos.into())) } } } } impl<'a> From<(&'a str, Pos)> for Error { fn from(value: (&'a str, Pos)) -> Self { ErrorKind::Pos(value.0.to_string(), value.1.into()).into() } } impl<'a> From<Reporter<'a>> for Error { fn from(value: Reporter<'a>) -> Self { let e: core::Error = value.into(); e.into() } }