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 too large in relation to consensus")]
20 DiffTooLarge,
21
22 #[error("Diff didn't apply to input: {0}")]
25 CantApply(&'static str),
26
27 #[error("Invalid input supplied: {0}")]
30 InvalidInput(parse2::ParseError),
31
32 #[error("Internal error")]
34 Bug(tor_error::Bug),
35}
36
37impl From<ParseIntError> for Error {
38 fn from(_e: ParseIntError) -> Error {
39 Error::BadDiff("can't parse line number")
40 }
41}
42impl From<hex::FromHexError> for Error {
43 fn from(_e: hex::FromHexError) -> Error {
44 Error::BadDiff("invalid hexadecimal in 'hash' line")
45 }
46}
47
48impl From<parse2::ParseError> for Error {
49 fn from(e: parse2::ParseError) -> Self {
50 Self::InvalidInput(e)
51 }
52}
53
54impl From<tor_error::Bug> for Error {
55 fn from(e: tor_error::Bug) -> Self {
56 Self::Bug(e)
57 }
58}
59
60#[derive(Clone, Debug, Error, PartialEq, Eq)]
65pub(crate) enum GenEdDiffError {
66 #[error("Line {lno} does not end with a Unix line ending")]
68 MissingUnixLineEnding {
69 lno: usize,
71 },
72
73 #[error("Dotline found at {lno}")]
76 ContainsDotLine {
77 lno: usize,
79 },
80
81 #[error("Formatting error: {0}")]
83 Write(#[from] std::fmt::Error),
84}