6 #include <zookeeper/zookeeper.h>
15 const std::array<error_code, ZKPP_ERROR_CODE_LIST(ZKPP_ERROR_CODE_SIZE_IMPL)>& all_error_codes()
17 #define ZKPP_ERROR_CODE_VALUE_IMPL(cxx_name, number, c_name) error_code::cxx_name,
18 static std::array<error_code, ZKPP_ERROR_CODE_LIST(ZKPP_ERROR_CODE_SIZE_IMPL)> instance =
20 ZKPP_ERROR_CODE_LIST(ZKPP_ERROR_CODE_VALUE_IMPL)
25 std::ostream& operator<<(std::ostream& os,
const error_code& code)
29 #define ZKPP_ERROR_CODE_OSTREAM_CASE_IMPL(cxx_name, number, c_name) \
30 case error_code::cxx_name: return os << #cxx_name;
31 ZKPP_ERROR_CODE_LIST(ZKPP_ERROR_CODE_OSTREAM_CASE_IMPL)
33 return os << "error_code(" << static_cast<
int>(code) << ')';
37 std::
string to_string(const error_code& code)
39 std::ostringstream os;
44 void throw_error(error_code code)
48 case error_code::runtime_inconsistency:
throw runtime_inconsistency();
49 case error_code::data_inconsistency:
throw data_inconsistency();
50 case error_code::connection_loss:
throw connection_loss();
51 case error_code::marshalling_error:
throw marshalling_error();
52 case error_code::unimplemented:
throw unimplemented();
53 case error_code::operation_timeout:
throw operation_timeout();
54 case error_code::invalid_arguments:
throw invalid_arguments();
55 case error_code::invalid_handle_state:
throw invalid_handle_state();
56 case error_code::unknown_session:
throw unknown_session();
57 case error_code::new_configuration_no_quorum:
throw new_configuration_no_quorum();
58 case error_code::reconfiguration_in_progress:
throw reconfiguration_in_progress();
59 case error_code::no_node:
throw no_node();
60 case error_code::not_authenticated:
throw not_authenticated();
61 case error_code::bad_version:
throw bad_version();
62 case error_code::no_children_for_ephemerals:
throw no_children_for_ephemerals();
63 case error_code::node_exists:
throw node_exists();
64 case error_code::not_empty:
throw not_empty();
65 case error_code::session_expired:
throw session_expired();
66 case error_code::invalid_callback:
throw invalid_callback();
67 case error_code::invalid_acl:
throw invalid_acl();
69 case error_code::closing:
throw closing();
70 case error_code::no_response:
throw no_response();
71 case error_code::session_moved:
throw session_moved();
72 case error_code::server_read_only:
throw server_read_only();
73 case error_code::ephemeral_on_local_session:
throw ephemeral_on_local_session();
74 case error_code::no_watcher:
throw no_watcher();
75 case error_code::reconfiguration_disabled:
throw reconfiguration_disabled();
76 case error_code::transaction_failed:
throw transaction_failed(code, 0);
77 default:
throw unknown_error(code);
81 std::exception_ptr get_exception_ptr_of(error_code code)
89 return std::current_exception();
97 error::error(error_code code, std::string description) :
98 std::runtime_error(to_string(code) +
": " + description),
102 error::~error() noexcept = default;
104 system_error::system_error(error_code code, std::
string description) :
105 error(code, std::move(description))
108 system_error::~system_error() noexcept = default;
110 runtime_inconsistency::runtime_inconsistency() :
111 system_error(error_code::runtime_inconsistency, "A runtime inconsistency was found")
114 runtime_inconsistency::~runtime_inconsistency() noexcept = default;
116 data_inconsistency::data_inconsistency() :
117 system_error(error_code::data_inconsistency, "A data inconsistency was found")
120 data_inconsistency::~data_inconsistency() noexcept = default;
122 connection_loss::connection_loss() :
123 system_error(error_code::connection_loss, "Connection to the server has been lost")
126 connection_loss::~connection_loss() noexcept = default;
128 marshalling_error::marshalling_error() :
129 system_error(error_code::marshalling_error, "Error while marshalling or unmarshalling data")
132 marshalling_error::~marshalling_error() noexcept = default;
134 unimplemented::unimplemented() :
135 system_error(error_code::unimplemented, "Operation is unimplemented")
138 unimplemented::~unimplemented() noexcept = default;
140 operation_timeout::operation_timeout() :
141 system_error(error_code::operation_timeout, "Operation timeout")
144 operation_timeout::~operation_timeout() noexcept = default;
146 invalid_arguments::invalid_arguments() :
147 system_error(error_code::invalid_arguments, "Invalid arguments")
150 invalid_arguments::~invalid_arguments() noexcept = default;
152 invalid_handle_state::invalid_handle_state() :
153 system_error(error_code::invalid_handle_state, "Invalid
state for handle")
156 invalid_handle_state::~invalid_handle_state() noexcept = default;
158 unknown_session::unknown_session() :
159 system_error(error_code::unknown_session, "Unknown
session")
162 unknown_session::~unknown_session() noexcept = default;
164 new_configuration_no_quorum::new_configuration_no_quorum() :
165 system_error(error_code::new_configuration_no_quorum,
166 "No quorum of new configuration is
connected and up-to-date with the leader of last commmitted "
167 "configuration. Try invoking reconfiguration after new servers are
connected and synced."
171 new_configuration_no_quorum::~new_configuration_no_quorum() noexcept = default;
173 reconfiguration_in_progress::reconfiguration_in_progress() :
174 system_error(error_code::reconfiguration_in_progress,
175 "Another reconfiguration is in progress -- concurrent reconfigs not supported"
179 reconfiguration_in_progress::~reconfiguration_in_progress() noexcept = default;
181 api_error::api_error(error_code code, std::
string description) :
182 error(code, std::move(description))
185 api_error::~api_error() noexcept = default;
188 api_error(error_code::no_node, "Node does not exist")
191 no_node::~no_node() noexcept = default;
193 not_authenticated::not_authenticated() :
194 api_error(error_code::not_authenticated, "Not authenticated")
197 not_authenticated::~not_authenticated() noexcept = default;
199 bad_version::bad_version() :
200 api_error(error_code::bad_version, "Version conflict")
203 bad_version::~bad_version() noexcept = default;
205 no_children_for_ephemerals::no_children_for_ephemerals() :
206 api_error(error_code::no_children_for_ephemerals, "Ephemeral nodes may not have children")
209 no_children_for_ephemerals::~no_children_for_ephemerals() noexcept = default;
211 node_exists::node_exists() :
212 api_error(error_code::node_exists, "Node already exists")
215 node_exists::~node_exists() noexcept = default;
217 not_empty::not_empty() :
218 api_error(error_code::not_empty, "Cannot
erase a node with children")
221 not_empty::~not_empty() noexcept = default;
223 session_expired::session_expired() :
224 api_error(error_code::session_expired, "The
session has been expired by the server")
227 session_expired::~session_expired() noexcept = default;
229 invalid_callback::invalid_callback() :
230 api_error(error_code::invalid_callback, "Invalid callback specified")
233 invalid_callback::~invalid_callback() noexcept = default;
235 invalid_acl::invalid_acl() :
236 api_error(error_code::invalid_acl, "Invalid ACL specified")
239 invalid_acl::~invalid_acl() noexcept = default;
245 authentication_failed::~authentication_failed() noexcept = default;
248 api_error(error_code::closing, "Client is closing")
251 closing::~closing() noexcept = default;
253 no_response::no_response() :
254 api_error(error_code::no_response, "No server responses to process")
257 no_response::~no_response() noexcept = default;
259 session_moved::session_moved() :
260 api_error(error_code::session_moved, "Session moved to another server, so operation was ignored")
263 session_moved::~session_moved() noexcept = default;
265 server_read_only::server_read_only() :
266 api_error(error_code::server_read_only, "State-changing request was passed to
read-only server")
269 server_read_only::~server_read_only() noexcept = default;
271 ephemeral_on_local_session::ephemeral_on_local_session() :
275 ephemeral_on_local_session::~ephemeral_on_local_session() noexcept = default;
277 no_watcher::no_watcher() :
278 api_error(error_code::no_watcher, "Cannot remove a non-existing watcher")
281 no_watcher::~no_watcher() noexcept = default;
283 reconfiguration_disabled::reconfiguration_disabled() :
284 api_error(error_code::reconfiguration_disabled, "Cluster reconfiguration feature is disabled")
287 reconfiguration_disabled::~reconfiguration_disabled() noexcept = default;
289 transaction_failed::transaction_failed(error_code underlying_cause, std::
size_t op_index) :
290 api_error(error_code::transaction_failed,
291 std::
string("Could not commit transaction due to ") + to_string(underlying_cause) + " on operation "
292 + std::to_string(op_index)
294 _underlying_cause(underlying_cause),
298 transaction_failed::~transaction_failed() noexcept = default;
300 unknown_error::unknown_error(error_code code) :
301 error(code, "Error code not recognized")
304 unknown_error::~unknown_error() noexcept = default;
This value is issued as part of an event when the state changes.
state
Enumeration of states the client may be at when a watch triggers.
Authentication has failed – connection requires a new connection instance with different credentials...
The client is in the connected state – it is connected to a server in the ensemble (one of the serve...
The znode will be deleted upon the client's disconnect.
Invalid event (this should never be issued).
You can create a child node.
You can access the data of a node and can list its children.
You can erase a child node (but not necessarily this one).