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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
use crate::deserialize::Deserialize;
use crate::protocol::{Field, ProtocolReader, ProtocolWriter};
use crate::serialize::Serialize;
use crate::thrift_protocol::ProtocolID;
use crate::ttype::TType;
use crate::Result;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(i32)]
pub enum ApplicationExceptionErrorCode {
Unknown = 0,
UnknownMethod = 1,
InvalidMessageType = 2,
WrongMethodName = 3,
BadSequenceID = 4,
MissingResult = 5,
InternalError = 6,
ProtocolError = 7,
InvalidTransform = 8,
InvalidProtocol = 9,
UnsupportedClientType = 10,
Loadshedding = 11,
Timeout = 12,
InjectedFailure = 13,
}
impl Default for ApplicationExceptionErrorCode {
fn default() -> Self {
ApplicationExceptionErrorCode::Unknown
}
}
const TAPPLICATION_EXCEPTION_ERROR_CODE: &str = "ApplicationExceptionErrorCode";
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
pub struct ApplicationException {
pub message: String,
pub type_: ApplicationExceptionErrorCode,
}
impl ApplicationException {
#[cold]
pub fn new(type_: ApplicationExceptionErrorCode, message: String) -> Self {
ApplicationException { message, type_ }
}
#[cold]
pub fn unimplemented_method(handler: &str, method: &str) -> Self {
ApplicationException {
type_: ApplicationExceptionErrorCode::UnknownMethod,
message: format!("Method {} not implemented for {}", method, handler),
}
}
#[inline]
pub fn unknown_method() -> Self {
ApplicationException {
type_: ApplicationExceptionErrorCode::UnknownMethod,
message: String::new(),
}
}
#[cold]
pub fn missing_arg(method: &str, arg: &str) -> Self {
ApplicationException {
type_: ApplicationExceptionErrorCode::ProtocolError,
message: format!("{} missing arg {}", method, arg),
}
}
#[cold]
pub fn missing_field(method: &str, field: &str) -> Self {
ApplicationException {
type_: ApplicationExceptionErrorCode::ProtocolError,
message: format!("Struct {} missing field {}", method, field),
}
}
#[cold]
pub fn invalid_protocol(badproto: ProtocolID) -> Self {
ApplicationException {
type_: ApplicationExceptionErrorCode::InvalidProtocol,
message: format!("Invalid protocol {:?}", badproto),
}
}
}
impl<P> Deserialize<P> for ApplicationException
where
P: ProtocolReader,
{
fn read(iprot: &mut P) -> Result<Self> {
iprot.read_struct_begin(|_| ())?;
let mut message = String::from("");
let mut type_ = ApplicationExceptionErrorCode::Unknown;
loop {
static FIELDS: &[Field] = &[
Field::new("message", TType::String, 1),
Field::new("type", TType::I32, 2),
];
let (_, ttype, id) = iprot.read_field_begin(|_| (), FIELDS)?;
match (ttype, id) {
(TType::Stop, _) => break,
(TType::String, 1) => message = iprot.read_string()?,
(TType::I32, 2) => {
type_ = match iprot.read_i32()? {
1 => ApplicationExceptionErrorCode::UnknownMethod,
2 => ApplicationExceptionErrorCode::InvalidMessageType,
3 => ApplicationExceptionErrorCode::WrongMethodName,
4 => ApplicationExceptionErrorCode::BadSequenceID,
5 => ApplicationExceptionErrorCode::MissingResult,
6 => ApplicationExceptionErrorCode::InternalError,
7 => ApplicationExceptionErrorCode::ProtocolError,
8 => ApplicationExceptionErrorCode::InvalidTransform,
9 => ApplicationExceptionErrorCode::InvalidProtocol,
10 => ApplicationExceptionErrorCode::UnsupportedClientType,
11 => ApplicationExceptionErrorCode::Loadshedding,
12 => ApplicationExceptionErrorCode::Timeout,
13 => ApplicationExceptionErrorCode::InjectedFailure,
_ => ApplicationExceptionErrorCode::Unknown,
}
}
(ttype, _) => iprot.skip(ttype)?,
};
iprot.read_field_end()?;
}
iprot.read_struct_end()?;
Ok(ApplicationException::new(type_, message))
}
}
impl<P> Serialize<P> for ApplicationException
where
P: ProtocolWriter,
{
fn write(&self, oprot: &mut P) {
oprot.write_struct_begin(TAPPLICATION_EXCEPTION_ERROR_CODE);
if !self.message.is_empty() {
oprot.write_field_begin("message", TType::String, 1);
oprot.write_string(&self.message);
oprot.write_field_end();
}
oprot.write_field_begin("type", TType::I32, 2);
oprot.write_i32(self.type_ as i32);
oprot.write_field_end();
oprot.write_field_stop();
oprot.write_struct_end();
}
}