1use std::{io, num};
6
7use failure::Fail;
8
9use crate::parser::Rule;
10
11#[derive(Debug, Fail)]
12pub enum Error {
13 #[fail(display = "Error reading: {}", _0)]
14 Reading(io::Error),
15 #[fail(display = "Error parsing patch: {}", _0)]
16 ParsingPatch(pest::error::Error<Rule>),
17 #[fail(display = "Error parsing context: {}", _0)]
18 ParsingContext(num::ParseIntError),
19 #[fail(display = "Missing an element: {}", _0)]
20 NotFound(&'static str),
21 #[fail(display = "Elements are found in invalid order: {}", _0)]
22 MalformedPatch(&'static str),
23 #[fail(display = "Line #{} not found", _0)]
24 AbruptInput(usize),
25 #[fail(display = "Invalid line #{}", _0)]
26 PatchInputMismatch(usize),
27}
28
29impl From<io::Error> for Error {
30 fn from(err: io::Error) -> Error {
31 Error::Reading(err)
32 }
33}
34
35impl From<pest::error::Error<Rule>> for Error {
36 fn from(err: pest::error::Error<Rule>) -> Error {
37 Error::ParsingPatch(err)
38 }
39}
40
41impl From<num::ParseIntError> for Error {
42 fn from(err: num::ParseIntError) -> Error {
43 Error::ParsingContext(err)
44 }
45}