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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use failure::{Error, Fail};
use toku_protocol::frames::GoAway;
use toku_protocol::upgrade::UpgradeFrame;
#[derive(Debug, Fail)]
pub enum TokuError {
#[fail(display = "TCP Connection closed.")]
TcpStreamClosed,
#[fail(display = "Connection close requested.")]
ConnectionCloseRequested,
#[fail(display = "Connection closed.")]
ConnectionClosed,
#[fail(display = "Invalid upgrade frame. frame={:?}", frame)]
InvalidUpgradeFrame { frame: UpgradeFrame },
#[fail(display = "Connection not ready.")]
NotReady,
#[fail(display = "Told to go away. go_away={:?}", go_away)]
ToldToGoAway { go_away: GoAway },
#[fail(
display = "Invalid Opcode. actual={:?} expected={:?}",
actual, expected
)]
InvalidOpcode { actual: u8, expected: Option<u8> },
#[fail(
display = "Unsupported Version. expected={} actual={}",
expected, actual
)]
UnsupportedVersion { expected: u8, actual: u8 },
#[fail(display = "No common encoding.")]
NoCommonEncoding,
#[fail(display = "No common compression.")]
NoCommonCompression,
#[fail(display = "Invalid encoding.")]
InvalidEncoding,
#[fail(display = "Invalid compression.")]
InvalidCompression,
#[fail(display = "Ping timeout.")]
PingTimeout,
#[fail(display = "Internal server error. error={:?}", error)]
InternalServerError { error: Error },
#[fail(display = "Event receive error.")]
EventReceiveError,
#[fail(display = "Ready send failed.")]
ReadySendFailed,
#[fail(display = "Request timeout.")]
RequestTimeout,
#[fail(display = "Reached max backoff elapsed time.")]
ReachedMaxBackoffElapsedTime,
#[fail(display = "No client encoding.")]
NoClientEncoding,
}
pub enum TokuErrorCode {
Normal = 0,
InvalidOpcode = 1,
UnsupportedVersion = 2,
NoCommonEncoding = 3,
InvalidEncoding = 4,
InvalidCompression = 5,
PingTimeout = 6,
InternalServerError = 7,
}
impl TokuError {
pub(crate) fn code(&self) -> TokuErrorCode {
match self {
TokuError::InvalidOpcode { .. } => TokuErrorCode::InvalidOpcode,
TokuError::UnsupportedVersion { .. } => TokuErrorCode::UnsupportedVersion,
TokuError::NoCommonEncoding { .. } => TokuErrorCode::NoCommonEncoding,
TokuError::InvalidEncoding => TokuErrorCode::InvalidEncoding,
TokuError::InvalidCompression => TokuErrorCode::InvalidCompression,
TokuError::PingTimeout => TokuErrorCode::PingTimeout,
TokuError::ConnectionCloseRequested => TokuErrorCode::Normal,
_ => TokuErrorCode::InternalServerError,
}
}
}