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