rocketmq_error/boundary.rs
1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/// Remoting response-code primitive.
16///
17/// This mirrors stable wire numbers without depending on the protocol or transport crates.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
19#[repr(i32)]
20pub enum RemotingResponseCode {
21 /// Represents the system error case.
22 SystemError = 1,
23 /// Represents the system busy case.
24 SystemBusy = 2,
25 /// Represents the request code not supported case.
26 RequestCodeNotSupported = 3,
27 /// Represents the service not available case.
28 ServiceNotAvailable = 14,
29 /// Represents the no permission case.
30 NoPermission = 16,
31 /// Represents the topic not exist case.
32 TopicNotExist = 17,
33 /// Represents the pull-offset-moved case.
34 PullOffsetMoved = 21,
35 /// Represents the query not found case.
36 QueryNotFound = 22,
37 /// Represents the subscription-parse-failed case.
38 SubscriptionParseFailed = 23,
39 /// Represents the subscription not exist case.
40 SubscriptionNotExist = 24,
41 /// Represents the subscription group not exist case.
42 SubscriptionGroupNotExist = 26,
43 /// Represents the invalid parameter case.
44 InvalidParameter = 29,
45 /// Represents the message illegal case.
46 MessageIllegal = 13,
47 /// Represents the broker not exist case.
48 BrokerNotExist = 211,
49 /// Represents the not leader for queue case.
50 NotLeaderForQueue = 501,
51 /// Represents the controller not leader case.
52 ControllerNotLeader = 2007,
53 /// Represents the controller jraft internal error case.
54 ControllerJraftInternalError = 2015,
55 /// Represents the user not exist case.
56 UserNotExist = 3001,
57}
58
59impl RemotingResponseCode {
60 #[inline]
61 /// Borrows this value as i32.
62 pub const fn as_i32(self) -> i32 {
63 self as i32
64 }
65}
66
67#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
68/// Represents remoting spec.
69pub struct RemotingSpec {
70 /// The code value.
71 pub code: RemotingResponseCode,
72}
73
74impl RemotingSpec {
75 #[inline]
76 /// Creates a new `RemotingSpec`.
77 pub const fn new(code: RemotingResponseCode) -> Self {
78 Self { code }
79 }
80}
81
82/// gRPC payload-code primitive.
83///
84/// This mirrors the proxy protobuf vocabulary without depending on generated
85/// protobuf types.
86#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
87pub enum GrpcPayloadCode {
88 /// Represents the internal error case.
89 InternalError,
90 /// Represents the bad request case.
91 BadRequest,
92 /// Represents the unauthorized case.
93 Unauthorized,
94 /// Represents the forbidden case.
95 Forbidden,
96 /// Represents the not found case.
97 NotFound,
98 /// Represents the topic not found case.
99 TopicNotFound,
100 /// Represents the consumer group not found case.
101 ConsumerGroupNotFound,
102 /// Represents the offset not found case.
103 OffsetNotFound,
104 /// Represents the illegal offset case.
105 IllegalOffset,
106 /// Represents the message not found case.
107 MessageNotFound,
108 /// Represents the message body too large case.
109 MessageBodyTooLarge,
110 /// Represents the request timeout case.
111 RequestTimeout,
112 /// Represents the proxy timeout case.
113 ProxyTimeout,
114 /// Represents the too many requests case.
115 TooManyRequests,
116 /// Represents the unsupported case.
117 Unsupported,
118 /// Represents a missing Proxy client identifier.
119 ClientIdRequired,
120 /// Represents an unrecognized Proxy client type.
121 UnrecognizedClientType,
122 /// Represents a Proxy capability that is not implemented.
123 NotImplemented,
124 /// Represents an illegal message identifier.
125 IllegalMessageId,
126 /// Represents an invalid transaction identifier.
127 InvalidTransactionId,
128 /// Represents an illegal message group.
129 IllegalMessageGroup,
130 /// Represents an illegal delivery time.
131 IllegalDeliveryTime,
132 /// Represents an illegal polling time.
133 IllegalPollingTime,
134 /// Represents an illegal invisible time.
135 IllegalInvisibleTime,
136 /// Represents an illegal filter expression.
137 IllegalFilterExpression,
138 /// Represents an invalid receipt handle.
139 InvalidReceiptHandle,
140 /// Represents an illegal lite topic.
141 IllegalLiteTopic,
142 /// Represents an exhausted lite-subscription quota.
143 LiteSubscriptionQuotaExceeded,
144 /// Represents a message property that conflicts with the message type.
145 MessagePropertyConflictWithType,
146}
147
148/// Transport-level gRPC status primitive.
149#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
150pub enum GrpcStatusCode {
151 /// Represents the invalid argument case.
152 InvalidArgument,
153 /// Represents the unauthenticated case.
154 Unauthenticated,
155 /// Represents the permission denied case.
156 PermissionDenied,
157 /// Represents the not found case.
158 NotFound,
159 /// Represents the already exists case.
160 AlreadyExists,
161 /// Represents the deadline exceeded case.
162 DeadlineExceeded,
163 /// Represents the resource exhausted case.
164 ResourceExhausted,
165 /// Represents the failed precondition case.
166 FailedPrecondition,
167 /// Represents the aborted case.
168 Aborted,
169 /// Represents the unimplemented case.
170 Unimplemented,
171 /// Represents the unavailable case.
172 Unavailable,
173 /// Represents the data loss case.
174 DataLoss,
175 /// Represents the internal case.
176 Internal,
177}
178
179#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
180/// Represents grpc spec.
181pub struct GrpcSpec {
182 /// The payload value.
183 pub payload: GrpcPayloadCode,
184 /// The status value.
185 pub status: GrpcStatusCode,
186}
187
188impl GrpcSpec {
189 #[inline]
190 /// Creates a new `GrpcSpec`.
191 pub const fn new(payload: GrpcPayloadCode, status: GrpcStatusCode) -> Self {
192 Self { payload, status }
193 }
194}
195
196/// HTTP status-code primitive.
197#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
198pub struct HttpStatusCode(u16);
199
200impl HttpStatusCode {
201 /// The bad request constant.
202 pub const BAD_REQUEST: Self = Self(400);
203 /// The unauthorized constant.
204 pub const UNAUTHORIZED: Self = Self(401);
205 /// The forbidden constant.
206 pub const FORBIDDEN: Self = Self(403);
207 /// The not found constant.
208 pub const NOT_FOUND: Self = Self(404);
209 /// The conflict constant.
210 pub const CONFLICT: Self = Self(409);
211 /// The request timeout constant.
212 pub const REQUEST_TIMEOUT: Self = Self(408);
213 /// The payload too large constant.
214 pub const PAYLOAD_TOO_LARGE: Self = Self(413);
215 /// The too many requests constant.
216 pub const TOO_MANY_REQUESTS: Self = Self(429);
217 /// The internal server error constant.
218 pub const INTERNAL_SERVER_ERROR: Self = Self(500);
219 /// The service unavailable constant.
220 pub const SERVICE_UNAVAILABLE: Self = Self(503);
221 /// The not implemented constant.
222 pub const NOT_IMPLEMENTED: Self = Self(501);
223 /// The gateway timeout constant.
224 pub const GATEWAY_TIMEOUT: Self = Self(504);
225 /// The insufficient storage constant.
226 pub const INSUFFICIENT_STORAGE: Self = Self(507);
227
228 #[inline]
229 /// Creates a new `HttpStatusCode`.
230 pub const fn new(value: u16) -> Self {
231 Self(value)
232 }
233
234 #[inline]
235 /// Borrows this value as u16.
236 pub const fn as_u16(self) -> u16 {
237 self.0
238 }
239}
240
241#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
242/// Represents http spec.
243pub struct HttpSpec {
244 /// The status value.
245 pub status: HttpStatusCode,
246}
247
248impl HttpSpec {
249 #[inline]
250 /// Creates a new `HttpSpec`.
251 pub const fn new(status: HttpStatusCode) -> Self {
252 Self { status }
253 }
254}
255
256/// CLI exit-code primitive.
257#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
258pub struct CliExitCode(i32);
259
260impl CliExitCode {
261 /// The data constant.
262 pub const DATA: Self = Self(65);
263 /// The not found constant.
264 pub const NOT_FOUND: Self = Self(66);
265 /// The unavailable constant.
266 pub const UNAVAILABLE: Self = Self(69);
267 /// The software constant.
268 pub const SOFTWARE: Self = Self(70);
269 /// The temporary failure constant.
270 pub const TEMPORARY_FAILURE: Self = Self(75);
271 /// The permission constant.
272 pub const PERMISSION: Self = Self(77);
273 /// The config constant.
274 pub const CONFIG: Self = Self(78);
275 /// The usage constant.
276 pub const USAGE: Self = Self(64);
277
278 #[inline]
279 /// Creates a new `CliExitCode`.
280 pub const fn new(value: i32) -> Self {
281 Self(value)
282 }
283
284 #[inline]
285 /// Borrows this value as i32.
286 pub const fn as_i32(self) -> i32 {
287 self.0
288 }
289}
290
291#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
292/// Represents cli spec.
293pub struct CliSpec {
294 /// The exit code value.
295 pub exit_code: CliExitCode,
296}
297
298impl CliSpec {
299 #[inline]
300 /// Creates a new `CliSpec`.
301 pub const fn new(exit_code: CliExitCode) -> Self {
302 Self { exit_code }
303 }
304}