1//! Declare an error type for the tor-consdiff crate.
23use thiserror::Error;
45use std::num::ParseIntError;
67/// 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}")]
15BadDiff(&'static str),
1617/// 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}")]
20CantApply(&'static str),
21}
2223impl From<ParseIntError> for Error {
24fn from(_e: ParseIntError) -> Error {
25 Error::BadDiff("can't parse line number")
26 }
27}
28impl From<hex::FromHexError> for Error {
29fn from(_e: hex::FromHexError) -> Error {
30 Error::BadDiff("invalid hexadecimal in 'hash' line")
31 }
32}