1use thiserror::Error;
4use tor_netdoc::parse2;
5
6use std::num::ParseIntError;
7
8#[derive(Clone, Debug, Error)]
10#[non_exhaustive]
11pub enum Error {
12 #[error("Invalid diff: {0}")]
16 BadDiff(&'static str),
17
18 #[error("Diff didn't apply to input: {0}")]
21 CantApply(&'static str),
22
23 #[error("Invalid input supplied: {0}")]
26 InvalidInput(parse2::ParseError),
27
28 #[error("Internal error")]
30 Bug(tor_error::Bug),
31}
32
33impl From<ParseIntError> for Error {
34 fn from(_e: ParseIntError) -> Error {
35 Error::BadDiff("can't parse line number")
36 }
37}
38impl From<hex::FromHexError> for Error {
39 fn from(_e: hex::FromHexError) -> Error {
40 Error::BadDiff("invalid hexadecimal in 'hash' line")
41 }
42}
43
44impl From<parse2::ParseError> for Error {
45 fn from(e: parse2::ParseError) -> Self {
46 Self::InvalidInput(e)
47 }
48}
49
50impl From<tor_error::Bug> for Error {
51 fn from(e: tor_error::Bug) -> Self {
52 Self::Bug(e)
53 }
54}
55
56#[derive(Clone, Debug, Error, PartialEq, Eq)]
61pub(crate) enum GenEdDiffError {
62 #[error("Line {lno} does not end with a Unix line ending")]
64 MissingUnixLineEnding {
65 lno: usize,
67 },
68
69 #[error("Dotline found at {lno}")]
72 ContainsDotLine {
73 lno: usize,
75 },
76
77 #[error("Formatting error: {0}")]
79 Write(#[from] std::fmt::Error),
80}