tor_consdiff/
err.rs

1//! Declare an error type for the tor-consdiff crate.
2
3use thiserror::Error;
4
5use std::num::ParseIntError;
6
7/// An error type from the tor-consdiff crate.
8#[derive(Clone, Debug, Error)]
9#[non_exhaustive]
10pub enum Error {
11    /// We got a consensus diff that we couldn't parse, or which we found
12    /// to be somehow invalid.
13    // TODO: it would be neat to have line numbers here.
14    #[error("Invalid diff: {0}")]
15    BadDiff(&'static str),
16
17    /// We got a consensus diff that looked valid, but we couldn't apply it
18    /// to the given input.
19    #[error("Diff didn't apply to input: {0}")]
20    CantApply(&'static str),
21}
22
23impl From<ParseIntError> for Error {
24    fn from(_e: ParseIntError) -> Error {
25        Error::BadDiff("can't parse line number")
26    }
27}
28impl From<hex::FromHexError> for Error {
29    fn from(_e: hex::FromHexError) -> Error {
30        Error::BadDiff("invalid hexadecimal in 'hash' line")
31    }
32}