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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use thiserror::Error;
use tor_error::{ErrorKind, HasKind};
#[derive(Error, Debug, Clone)]
#[non_exhaustive]
pub enum Error {
#[error("Error while parsing {parsed}")]
BytesErr {
#[source]
err: tor_bytes::Error,
parsed: &'static str,
},
#[error("Error while encoding message")]
EncodeErr(#[from] tor_bytes::EncodeError),
#[error("Internal programming error")]
Internal(tor_error::Bug),
#[error("Channel protocol violation: {0}")]
ChanProto(String),
#[error("Invalid stream target address")]
BadStreamAddress,
#[error("Message can't be represented in a Tor cell: {0}")]
CantEncode(&'static str),
}
impl HasKind for Error {
fn kind(&self) -> ErrorKind {
use tor_bytes::Error as ByE;
use Error as E;
use ErrorKind as EK;
match self {
E::BytesErr {
err: ByE::Truncated,
..
} => EK::Internal,
E::EncodeErr(..) => EK::BadApiUsage,
E::BytesErr { .. } => EK::TorProtocolViolation,
E::Internal(_) => EK::Internal,
E::ChanProto(_) => EK::TorProtocolViolation,
E::BadStreamAddress => EK::BadApiUsage,
E::CantEncode(_) => EK::Internal,
}
}
}