Hazelcast C++ Client
Hazelcast C++ Client Library
protocol_exceptions.h
1 /*
2  * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <boost/uuid/nil_generator.hpp>
20 
21 #include "hazelcast/client/exception/iexception.h"
22 #include "hazelcast/client/protocol/ClientProtocolErrorCodes.h"
23 
24 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
25 #pragma warning(push)
26 #pragma warning(disable : 4251) // for dll export
27 #endif
28 
29 namespace hazelcast {
30 namespace client {
31 namespace exception {
32 #define DEFINE_EXCEPTION_CLASS(ClassName, errorNo, isRuntime) \
33  class HAZELCAST_API ClassName : public iexception \
34  { \
35  public: \
36  ClassName(std::string source, \
37  std::string message, \
38  std::string details = "", \
39  std::exception_ptr cause = nullptr, \
40  bool retryable = false) \
41  : ClassName(#ClassName, \
42  errorNo, \
43  std::move(source), \
44  std::move(message), \
45  std::move(details), \
46  std::move(cause), \
47  isRuntime, \
48  retryable) \
49  { \
50  } \
51  explicit ClassName(std::string message) \
52  : ClassName("", std::move(message)) \
53  { \
54  } \
55  ClassName() \
56  : ClassName("", "") \
57  { \
58  } \
59  ClassName(std::string errorName, \
60  int32_t errorCode, \
61  std::string source, \
62  std::string message, \
63  std::string details, \
64  std::exception_ptr cause, \
65  bool runtime, \
66  bool retryable) \
67  : iexception(std::move(errorName), \
68  std::move(source), \
69  std::move(message), \
70  std::move(details), \
71  errorCode, \
72  std::move(cause), \
73  runtime, \
74  retryable) \
75  { \
76  } \
77  };
78 
79 // --------- Non-runtime starts here
80 // -------------------------------------------/
81 DEFINE_EXCEPTION_CLASS(undefined_error_code, protocol::UNDEFINED, false);
82 
83 DEFINE_EXCEPTION_CLASS(execution, protocol::EXECUTION, false);
84 
85 DEFINE_EXCEPTION_CLASS(class_not_found, protocol::CLASS_NOT_FOUND, false);
86 
87 DEFINE_EXCEPTION_CLASS(eof, protocol::ENDOFFILE, false);
88 
89 DEFINE_EXCEPTION_CLASS(io, protocol::IO, false);
90 
91 DEFINE_EXCEPTION_CLASS(illegal_access,
92  protocol::ILLEGAL_ACCESS_EXCEPTION,
93  false);
94 
95 DEFINE_EXCEPTION_CLASS(illegal_access_error,
96  protocol::ILLEGAL_ACCESS_ERROR,
97  false);
98 
99 DEFINE_EXCEPTION_CLASS(interrupted, protocol::INTERRUPTED, false);
100 
101 DEFINE_EXCEPTION_CLASS(not_serializable, protocol::NOT_SERIALIZABLE, false);
102 
103 DEFINE_EXCEPTION_CLASS(socket, protocol::SOCK_ERROR, false);
104 
105 DEFINE_EXCEPTION_CLASS(timeout, protocol::TIMEOUT, false);
106 DEFINE_EXCEPTION_CLASS(uri_syntax, protocol::URI_SYNTAX, false);
107 DEFINE_EXCEPTION_CLASS(utf_data_format, protocol::UTF_DATA_FORMAT, false);
108 DEFINE_EXCEPTION_CLASS(xa, protocol::XA, false);
109 DEFINE_EXCEPTION_CLASS(login, protocol::LOGIN, false);
110 DEFINE_EXCEPTION_CLASS(unsupported_callback,
111  protocol::UNSUPPORTED_CALLBACK,
112  false);
113 DEFINE_EXCEPTION_CLASS(assertion_error, protocol::ASSERTION_ERROR, false);
114 DEFINE_EXCEPTION_CLASS(out_of_memory_error,
115  protocol::OUT_OF_MEMORY_ERROR,
116  false);
117 DEFINE_EXCEPTION_CLASS(stack_overflow_error,
118  protocol::STACK_OVERFLOW_ERROR,
119  false);
120 DEFINE_EXCEPTION_CLASS(native_out_of_memory_error,
121  protocol::NATIVE_OUT_OF_MEMORY_ERROR,
122  false);
123 // --------- Non-runtime ends here -------------------------------------------/
124 
125 // --------- runtime starts here -------------------------------------------/
126 DEFINE_EXCEPTION_CLASS(array_index_out_of_bounds,
127  protocol::INDEX_OUT_OF_BOUNDS,
128  true);
129 DEFINE_EXCEPTION_CLASS(array_store, protocol::ARRAY_STORE, true);
130 DEFINE_EXCEPTION_CLASS(authentication, protocol::AUTHENTICATION, true);
131 DEFINE_EXCEPTION_CLASS(cache_not_exists, protocol::CACHE_NOT_EXISTS, true);
132 DEFINE_EXCEPTION_CLASS(cancellation, protocol::CANCELLATION, true);
133 DEFINE_EXCEPTION_CLASS(class_cast, protocol::CLASS_CAST, true);
134 DEFINE_EXCEPTION_CLASS(concurrent_modification,
135  protocol::CONCURRENT_MODIFICATION,
136  true);
137 DEFINE_EXCEPTION_CLASS(config_mismatch, protocol::CONFIG_MISMATCH, true);
138 DEFINE_EXCEPTION_CLASS(distributed_object_destroyed,
139  protocol::DISTRIBUTED_OBJECT_DESTROYED,
140  true);
141 DEFINE_EXCEPTION_CLASS(entry_processor, protocol::ENTRY_PROCESSOR, true);
142 DEFINE_EXCEPTION_CLASS(hazelcast_, protocol::HAZELCAST, true);
143 DEFINE_EXCEPTION_CLASS(hazelcast_instance_not_active,
144  protocol::HAZELCAST_INSTANCE_NOT_ACTIVE,
145  true);
146 DEFINE_EXCEPTION_CLASS(hazelcast_overload, protocol::HAZELCAST_OVERLOAD, true);
147 DEFINE_EXCEPTION_CLASS(hazelcast_serialization,
148  protocol::HAZELCAST_SERIALIZATION,
149  true);
150 DEFINE_EXCEPTION_CLASS(illegal_argument, protocol::ILLEGAL_ARGUMENT, true);
151 DEFINE_EXCEPTION_CLASS(illegal_monitor_state,
152  protocol::ILLEGAL_MONITOR_STATE,
153  true);
154 DEFINE_EXCEPTION_CLASS(illegal_state, protocol::ILLEGAL_STATE, true);
155 DEFINE_EXCEPTION_CLASS(illegal_thread_state,
156  protocol::ILLEGAL_THREAD_STATE,
157  true);
158 DEFINE_EXCEPTION_CLASS(index_out_of_bounds,
159  protocol::INDEX_OUT_OF_BOUNDS,
160  true);
161 DEFINE_EXCEPTION_CLASS(invalid_address, protocol::INVALID_ADDRESS, true);
162 DEFINE_EXCEPTION_CLASS(invalid_configuration,
163  protocol::INVALID_CONFIGURATION,
164  true);
165 DEFINE_EXCEPTION_CLASS(negative_array_size,
166  protocol::NEGATIVE_ARRAY_SIZE,
167  true);
168 DEFINE_EXCEPTION_CLASS(no_such_element, protocol::NO_SUCH_ELEMENT, true);
169 DEFINE_EXCEPTION_CLASS(null_pointer, protocol::NULL_POINTER, true);
170 DEFINE_EXCEPTION_CLASS(operation_timeout, protocol::OPERATION_TIMEOUT, true);
171 DEFINE_EXCEPTION_CLASS(query_result_size_exceeded,
172  protocol::QUERY_RESULT_SIZE_EXCEEDED,
173  true);
174 DEFINE_EXCEPTION_CLASS(split_brain_protection,
175  protocol::SPLIT_BRAIN_PROTECTION,
176  true);
177 DEFINE_EXCEPTION_CLASS(reached_max_size, protocol::REACHED_MAX_SIZE, true);
178 DEFINE_EXCEPTION_CLASS(rejected_execution, protocol::REJECTED_EXECUTION, true);
179 DEFINE_EXCEPTION_CLASS(response_already_sent,
180  protocol::RESPONSE_ALREADY_SENT,
181  true);
182 DEFINE_EXCEPTION_CLASS(runtime, protocol::RUNTIME, true);
183 DEFINE_EXCEPTION_CLASS(SecurityException, protocol::SECURITY, true);
188 DEFINE_EXCEPTION_CLASS(stale_sequence, protocol::STALE_SEQUENCE, true);
189 DEFINE_EXCEPTION_CLASS(target_disconnected,
190  protocol::TARGET_DISCONNECTED,
191  true);
192 DEFINE_EXCEPTION_CLASS(topic_overload, protocol::TOPIC_OVERLOAD, true);
193 
194 DEFINE_EXCEPTION_CLASS(transaction, protocol::TRANSACTION, true);
195 DEFINE_EXCEPTION_CLASS(transaction_not_active,
196  protocol::TRANSACTION_NOT_ACTIVE,
197  true);
198 DEFINE_EXCEPTION_CLASS(transaction_timed_out,
199  protocol::TRANSACTION_TIMED_OUT,
200  true);
201 DEFINE_EXCEPTION_CLASS(unsupported_operation,
202  protocol::UNSUPPORTED_OPERATION,
203  true);
204 DEFINE_EXCEPTION_CLASS(access_control, protocol::ACCESS_CONTROL, true);
205 DEFINE_EXCEPTION_CLASS(no_data_member_in_cluster,
206  protocol::NO_DATA_MEMBER,
207  true);
208 DEFINE_EXCEPTION_CLASS(replicated_map_cant_be_created_on_lite_member,
209  protocol::REPLICATED_MAP_CANT_BE_CREATED,
210  true);
211 DEFINE_EXCEPTION_CLASS(max_message_size_exceeded,
212  protocol::MAX_MESSAGE_SIZE_EXCEEDED,
213  true);
214 DEFINE_EXCEPTION_CLASS(wan_replication_queue_full,
215  protocol::WAN_REPLICATION_QUEUE_FULL,
216  true);
217 DEFINE_EXCEPTION_CLASS(service_not_found, protocol::SERVICE_NOT_FOUND, true);
218 
219 DEFINE_EXCEPTION_CLASS(stale_task_id, protocol::STALE_TASK_ID, true);
220 
221 DEFINE_EXCEPTION_CLASS(duplicate_task, protocol::DUPLICATE_TASK, true);
222 
223 DEFINE_EXCEPTION_CLASS(stale_task, protocol::STALE_TASK, true);
224 
225 DEFINE_EXCEPTION_CLASS(local_member_reset, protocol::LOCAL_MEMBER_RESET, true);
226 
227 DEFINE_EXCEPTION_CLASS(indeterminate_operation_state,
228  protocol::INDETERMINATE_OPERATION_STATE,
229  true);
230 
231 DEFINE_EXCEPTION_CLASS(node_id_out_of_range,
232  protocol::FLAKE_ID_NODE_ID_OUT_OF_RANGE_EXCEPTION,
233  true);
234 
235 DEFINE_EXCEPTION_CLASS(mutation_disallowed,
236  protocol::MUTATION_DISALLOWED_EXCEPTION,
237  true);
238 
239 DEFINE_EXCEPTION_CLASS(session_expired,
240  protocol::SESSION_EXPIRED_EXCEPTION,
241  true);
242 
243 DEFINE_EXCEPTION_CLASS(wait_key_cancelled,
244  protocol::WAIT_KEY_CANCELLED_EXCEPTION,
245  true);
246 
247 DEFINE_EXCEPTION_CLASS(lock_acquire_limit_reached,
248  protocol::LOCK_ACQUIRE_LIMIT_REACHED_EXCEPTION,
249  true);
250 
251 DEFINE_EXCEPTION_CLASS(lock_ownership_lost,
252  protocol::LOCK_OWNERSHIP_LOST_EXCEPTION,
253  true);
254 
255 DEFINE_EXCEPTION_CLASS(cp_group_destroyed,
256  protocol::CP_GROUP_DESTROYED_EXCEPTION,
257  true);
258 
259 DEFINE_EXCEPTION_CLASS(cannot_replicate,
260  protocol::CANNOT_REPLICATE_EXCEPTION,
261  true);
262 
263 DEFINE_EXCEPTION_CLASS(leader_demoted,
264  protocol::LEADER_DEMOTED_EXCEPTION,
265  true);
266 
267 DEFINE_EXCEPTION_CLASS(stale_append_request,
268  protocol::STALE_APPEND_REQUEST_EXCEPTION,
269  true);
270 
271 DEFINE_EXCEPTION_CLASS(not_leader, protocol::NOT_LEADER_EXCEPTION, true);
272 
273 DEFINE_EXCEPTION_CLASS(version_mismatch,
274  protocol::VERSION_MISMATCH_EXCEPTION,
275  true);
276 
277 class HAZELCAST_API retryable_hazelcast : public hazelcast_
278 {
279 public:
280  retryable_hazelcast(std::string error_name,
281  int32_t error_code,
282  std::string source,
283  std::string message,
284  std::string details,
285  std::exception_ptr cause,
286  bool runtime,
287  bool retryable);
288 
289  explicit retryable_hazelcast(std::string source = "",
290  std::string message = "",
291  std::string details = "",
292  std::exception_ptr cause = nullptr);
293 };
294 
295 #define DEFINE_RETRYABLE_EXCEPTION_CLASS(ClassName, errorNo) \
296  class HAZELCAST_API ClassName : public retryable_hazelcast \
297  { \
298  public: \
299  explicit ClassName(std::string source = "", \
300  std::string message = "", \
301  std::string details = "", \
302  std::exception_ptr cause = nullptr) \
303  : retryable_hazelcast(#ClassName, \
304  errorNo, \
305  std::move(source), \
306  std::move(message), \
307  std::move(details), \
308  std::move(cause), \
309  false, \
310  true) \
311  { \
312  } \
313  };
314 
316 DEFINE_RETRYABLE_EXCEPTION_CLASS(caller_not_member,
317  protocol::CALLER_NOT_MEMBER);
318 DEFINE_RETRYABLE_EXCEPTION_CLASS(partition_migrating,
319  protocol::PARTITION_MIGRATING);
320 DEFINE_RETRYABLE_EXCEPTION_CLASS(retryable_io, protocol::RETRYABLE_IO);
321 DEFINE_RETRYABLE_EXCEPTION_CLASS(target_not_member,
322  protocol::TARGET_NOT_MEMBER);
323 DEFINE_RETRYABLE_EXCEPTION_CLASS(wrong_target, protocol::WRONG_TARGET);
324 
325 DEFINE_RETRYABLE_EXCEPTION_CLASS(target_not_replica,
326  protocol::TARGET_NOT_REPLICA_EXCEPTION);
327 
328 class HAZELCAST_API query : public hazelcast_
329 {
330 public:
331  explicit query(std::string source = "",
332  std::string message = "",
333  std::string details = "",
334  std::exception_ptr cause = nullptr);
335 
336  query(int32_t code,
337  std::string message,
338  std::exception_ptr cause = nullptr,
339  boost::uuids::uuid originating_member_id = boost::uuids::nil_uuid(),
340  std::string suggestion = "");
341 
342  int32_t code() const;
343 
344  const std::string& suggestion() const;
345 
346  const boost::uuids::uuid& originating_member_uuid() const;
347 
348 private:
349  int32_t code_;
350  std::string suggestion_;
351  boost::uuids::uuid originating_member_uuid_;
352 };
353 
354 class HAZELCAST_API member_left : public execution
355 {
356 public:
357  explicit member_left(std::string source = "",
358  std::string message = "",
359  std::string details = "",
360  std::exception_ptr cause = nullptr);
361 };
362 
363 // --------- runtime ends here
364 // -------------------------------------------------/
365 
366 // ----------------- ONLY Client side exceptions start here
367 // ----------------------------------------
368 // ----------------- Client side runtime exceptions start here
369 // --------------------------------
370 class HAZELCAST_API consistency_lost : public hazelcast_
371 {
372 public:
373  explicit consistency_lost(std::string source = "",
374  std::string message = "",
375  std::string details = "",
376  std::exception_ptr cause = nullptr);
377 };
378 
379 DEFINE_EXCEPTION_CLASS(hazelcast_client_not_active,
380  protocol::HAZELCAST_INSTANCE_NOT_ACTIVE,
381  true);
382 
383 DEFINE_EXCEPTION_CLASS(hazelcast_client_offline,
384  protocol::HAZELCAST_CLIENT_OFFLINE,
385  true);
386 
387 // ----------------- Client side runtime exceptions finish here
388 // --------------------------------
389 
390 // ----------------- Client side non-runtime exceptions start here
391 // -----------------------------
395 DEFINE_EXCEPTION_CLASS(unknown_host, protocol::UNKNOWN_HOST, false);
396 
397 DEFINE_EXCEPTION_CLASS(client_not_allowed_in_cluster,
398  protocol::CLIENT_NOT_ALLOWED_IN_CLUSTER,
399  true);
400 // ----------------- Client side non-runtime exceptions finish here
401 // ----------------------------
402 
403 // ----------------- Client side runtime exceptions ends here
404 // --------------------------------
405 } // namespace exception
406 } // namespace client
407 } // namespace hazelcast
408 
409 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
410 #pragma warning(pop)
411 #endif