zookeeper-cpp
ZooKeeper Client for C++
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups
error.hpp
1 #pragma once
2 
3 #include <zk/config.hpp>
4 
5 #include <array>
6 #include <iosfwd>
7 #include <stdexcept>
8 #include <string>
9 
10 namespace zk
11 {
12 
17 #define ZKPP_ERROR_CODE_LIST(item) \
18  item(ok, 0, ZOK) \
19  item(system_error, -1, ZSYSTEMERROR) \
20  item(runtime_inconsistency, -2, ZRUNTIMEINCONSISTENCY) \
21  item(data_inconsistency, -3, ZDATAINCONSISTENCY) \
22  item(connection_loss, -4, ZCONNECTIONLOSS) \
23  item(marshalling_error, -5, ZMARSHALLINGERROR) \
24  item(unimplemented, -6, ZUNIMPLEMENTED) \
25  item(operation_timeout, -7, ZOPERATIONTIMEOUT) \
26  item(invalid_arguments, -8, ZBADARGUMENTS) \
27  item(invalid_handle_state, -9, ZINVALIDSTATE) \
28  item(unknown_session, -12, ZUNKNOWNSESSION) \
29  item(new_configuration_no_quorum, -13, ZNEWCONFIGNOQUORUM) \
30  item(reconfiguration_in_progress, -14, ZRECONFIGINPROGRESS) \
31  item(api_error, -100, ZAPIERROR) \
32  item(no_node, -101, ZNONODE) \
33  item(not_authenticated, -102, ZNOAUTH) \
34  item(bad_version, -103, ZBADVERSION) \
35  item(no_children_for_ephemerals, -108, ZNOCHILDRENFOREPHEMERALS) \
36  item(node_exists, -110, ZNODEEXISTS) \
37  item(not_empty, -111, ZNOTEMPTY) \
38  item(session_expired, -112, ZSESSIONEXPIRED) \
39  item(invalid_callback, -113, ZINVALIDCALLBACK) \
40  item(invalid_acl, -114, ZINVALIDACL) \
41  item(authentication_failed, -115, ZAUTHFAILED) \
42  item(closing, -116, ZCLOSING) \
43  item(no_response, -117, ZNOTHING) \
44  item(session_moved, -118, ZSESSIONMOVED) \
45  item(server_read_only, -119, ZNOTREADONLY) \
46  item(ephemeral_on_local_session, -120, ZEPHEMERALONLOCALSESSION) \
47  item(no_watcher, -121, ZNOWATCHER) \
48  item(reconfiguration_disabled, -123, ZRECONFIGDISABLED) \
49  item(transaction_failed, -199, ZTRANSACTIONFAILED) \
50 
51 enum class error_code : int
52 {
53  #define ZKPP_ERROR_CODE_ENUM_DEF_IMPL(cxx_name, number, c_name) \
54  cxx_name = number,
55 
56  ZKPP_ERROR_CODE_LIST(ZKPP_ERROR_CODE_ENUM_DEF_IMPL)
57 };
58 
59 std::ostream& operator<<(std::ostream&, const error_code&);
60 
61 std::string to_string(const error_code&);
62 
63 #define ZKPP_ERROR_CODE_SIZE_IMPL(cxx_name, number, c_name) +1
64 
65 const std::array<error_code, ZKPP_ERROR_CODE_LIST(ZKPP_ERROR_CODE_SIZE_IMPL)>& all_error_codes();
66 
67 constexpr bool is_system_error(error_code code)
68 {
69  return static_cast<int>(code) <= static_cast<int>(error_code::system_error)
70  && static_cast<int>(code) > static_cast<int>(error_code::api_error);
71 }
72 
73 constexpr bool is_api_error(error_code code)
74 {
75  return static_cast<int>(code) <= static_cast<int>(error_code::api_error);
76 }
77 
78 [[noreturn]]
79 void throw_error(error_code code);
80 
81 std::exception_ptr get_exception_ptr_of(error_code code);
82 
83 class error :
84  public std::runtime_error
85 {
86 public:
87  explicit error(error_code code, std::string description);
88 
89  virtual ~error() noexcept;
90 
91  error_code code() const { return _code; }
92 
93 private:
94  error_code _code;
95 };
96 
97 class system_error :
98  public error
99 {
100 public:
101  explicit system_error(error_code code, std::string description);
102 
103  virtual ~system_error() noexcept;
104 };
105 
107  public system_error
108 {
109 public:
110  explicit runtime_inconsistency();
111 
112  virtual ~runtime_inconsistency() noexcept;
113 };
114 
115 class data_inconsistency final :
116  public system_error
117 {
118 public:
119  explicit data_inconsistency();
120 
121  virtual ~data_inconsistency() noexcept;
122 };
123 
124 class connection_loss final :
125  public system_error
126 {
127 public:
128  explicit connection_loss();
129 
130  virtual ~connection_loss() noexcept;
131 };
132 
133 class marshalling_error final :
134  public system_error
135 {
136 public:
137  explicit marshalling_error();
138 
139  virtual ~marshalling_error() noexcept;
140 };
141 
142 class unimplemented final :
143  public system_error
144 {
145 public:
146  explicit unimplemented();
147 
148  virtual ~unimplemented() noexcept;
149 };
150 
151 class operation_timeout final :
152  public system_error
153 {
154 public:
155  explicit operation_timeout();
156 
157  virtual ~operation_timeout() noexcept;
158 };
159 
160 class invalid_arguments final :
161  public system_error
162 {
163 public:
164  explicit invalid_arguments();
165 
166  virtual ~invalid_arguments() noexcept;
167 };
168 
169 class invalid_handle_state final :
170  public system_error
171 {
172 public:
173  explicit invalid_handle_state();
174 
175  virtual ~invalid_handle_state() noexcept;
176 };
177 
178 class unknown_session final :
179  public system_error
180 {
181 public:
182  explicit unknown_session();
183 
184  virtual ~unknown_session() noexcept;
185 };
186 
188  public system_error
189 {
190 public:
191  explicit new_configuration_no_quorum();
192 
193  virtual ~new_configuration_no_quorum() noexcept;
194 };
195 
197  public system_error
198 {
199 public:
200  explicit reconfiguration_in_progress();
201 
202  virtual ~reconfiguration_in_progress() noexcept;
203 };
204 
205 class api_error :
206  public error
207 {
208 public:
209  explicit api_error(error_code code, std::string description);
210 
211  virtual ~api_error() noexcept;
212 };
213 
214 class no_node final :
215  public api_error
216 {
217 public:
218  explicit no_node();
219 
220  virtual ~no_node() noexcept;
221 };
222 
223 class not_authenticated final :
224  public api_error
225 {
226 public:
227  explicit not_authenticated();
228 
229  virtual ~not_authenticated() noexcept;
230 };
231 
232 class bad_version final :
233  public api_error
234 {
235 public:
236  explicit bad_version();
237 
238  virtual ~bad_version() noexcept;
239 };
240 
242  public api_error
243 {
244 public:
245  explicit no_children_for_ephemerals();
246 
247  virtual ~no_children_for_ephemerals() noexcept;
248 };
249 
250 class node_exists final :
251  public api_error
252 {
253 public:
254  explicit node_exists();
255 
256  virtual ~node_exists() noexcept;
257 };
258 
259 class not_empty final :
260  public api_error
261 {
262 public:
263  explicit not_empty();
264 
265  virtual ~not_empty() noexcept;
266 };
267 
268 class session_expired final :
269  public api_error
270 {
271 public:
272  explicit session_expired();
273 
274  virtual ~session_expired() noexcept;
275 };
276 
277 class invalid_callback final :
278  public api_error
279 {
280 public:
281  explicit invalid_callback();
282 
283  virtual ~invalid_callback() noexcept;
284 };
285 
286 class invalid_acl final :
287  public api_error
288 {
289 public:
290  explicit invalid_acl();
291 
292  virtual ~invalid_acl() noexcept;
293 };
294 
296  public api_error
297 {
298 public:
299  explicit authentication_failed();
300 
301  virtual ~authentication_failed() noexcept;
302 };
303 
304 class closing final :
305  public api_error
306 {
307 public:
308  explicit closing();
309 
310  virtual ~closing() noexcept;
311 };
312 
313 class no_response final :
314  public api_error
315 {
316 public:
317  explicit no_response();
318 
319  virtual ~no_response() noexcept;
320 };
321 
322 class session_moved final :
323  public api_error
324 {
325 public:
326  explicit session_moved();
327 
328  virtual ~session_moved() noexcept;
329 };
330 
331 class server_read_only final :
332  public api_error
333 {
334 public:
335  explicit server_read_only();
336 
337  virtual ~server_read_only() noexcept;
338 };
339 
341  public api_error
342 {
343 public:
344  explicit ephemeral_on_local_session();
345 
346  virtual ~ephemeral_on_local_session() noexcept;
347 };
348 
349 class no_watcher final :
350  public api_error
351 {
352 public:
353  explicit no_watcher();
354 
355  virtual ~no_watcher() noexcept;
356 };
357 
359  public api_error
360 {
361 public:
362  explicit reconfiguration_disabled();
363 
364  virtual ~reconfiguration_disabled() noexcept;
365 };
366 
370 class transaction_failed final :
371  public api_error
372 {
373 public:
374  explicit transaction_failed(error_code code, std::size_t op_index);
375 
376  virtual ~transaction_failed() noexcept;
377 
381  error_code underlying_cause() const { return _underlying_cause; }
382 
386  std::size_t failed_op_index() const { return _op_index; }
387 
388 private:
389  error_code _underlying_cause;
390  std::size_t _op_index;
391 };
392 
393 class unknown_error final :
394  public error
395 {
396 public:
397  explicit unknown_error(error_code code);
398 
399  virtual ~unknown_error() noexcept;
400 };
401 
404 }
std::size_t failed_op_index() const
The transaction index which caused the error (0 indexed).
Definition: error.hpp:386
error_code underlying_cause() const
The underlying cause that caused this transaction to be aborted.
Definition: error.hpp:381
Thrown from client::commit when a transaction cannot be committed to the system.
Definition: error.hpp:370