Merge lp:~hazmat/txzookeeper/errors-with-path into lp:txzookeeper

Proposed by Kapil Thangavelu on 2011-09-27
Status: Merged
Approved by: Jim Baker on 2011-10-01
Approved revision: 44
Merged at revision: 50
Proposed branch: lp:~hazmat/txzookeeper/errors-with-path
Merge into: lp:txzookeeper
Diff against target: 160 lines (+20/-18)
1 file modified
txzookeeper/client.py (+20/-18)
To merge this branch: bzr merge lp:~hazmat/txzookeeper/errors-with-path
Reviewer Review Type Date Requested Status
Jim Baker (community) Approve on 2011-10-01
Gustavo Niemeyer 2011-09-27 Approve on 2011-09-28
Review via email: mp+77254@code.launchpad.net

Description of the change

Errors should include path information.

Its very helpful when debugging zk error messages to know what the actual path
that caused the error was.

To post a comment you must log in.
Gustavo Niemeyer (niemeyer) wrote :

<niemeyer> hazmat: Very nice
<niemeyer> hazmat: I suggest adding a colon here:
<niemeyer> + error_msg += " %s" % path
<niemeyer> error_msg += ": %s" % path
<niemeyer> hazmat: +1 either way

review: Approve
Jim Baker (jimbaker) wrote :

+1, simple change and does provide useful info

review: Approve
45. By Kapil Thangavelu on 2012-02-03

merge trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'txzookeeper/client.py'
--- txzookeeper/client.py 2011-12-06 21:21:29 +0000
+++ txzookeeper/client.py 2012-02-03 15:13:22 +0000
@@ -174,7 +174,7 @@
174 d.errback(NotConnectedException("not connected"))174 d.errback(NotConnectedException("not connected"))
175 return d175 return d
176176
177 def _check_result(self, result_code, deferred, extra_codes=()):177 def _check_result(self, result_code, deferred, extra_codes=(), path=None):
178 """Check an API call or result for errors.178 """Check an API call or result for errors.
179179
180 :param result_code: The api result code.180 :param result_code: The api result code.
@@ -187,6 +187,8 @@
187 error = None187 error = None
188 if not result_code == zookeeper.OK and not result_code in extra_codes:188 if not result_code == zookeeper.OK and not result_code in extra_codes:
189 error_msg = zookeeper.zerror(result_code)189 error_msg = zookeeper.zerror(result_code)
190 if path is not None:
191 error_msg += " %s" % path
190 error_class = ERROR_MAPPING.get(192 error_class = ERROR_MAPPING.get(
191 result_code, zookeeper.ZooKeeperException)193 result_code, zookeeper.ZooKeeperException)
192 error = error_class(error_msg)194 error = error_class(error_msg)
@@ -213,14 +215,14 @@
213 return d215 return d
214216
215 def _cb_get(result_code, value, stat):217 def _cb_get(result_code, value, stat):
216 if self._check_result(result_code, d):218 if self._check_result(result_code, d, path=path):
217 return219 return
218 d.callback((value, stat))220 d.callback((value, stat))
219221
220 callback = self._zk_thread_callback(_cb_get)222 callback = self._zk_thread_callback(_cb_get)
221 watcher = self._wrap_watcher(watcher)223 watcher = self._wrap_watcher(watcher)
222 result = zookeeper.aget(self.handle, path, watcher, callback)224 result = zookeeper.aget(self.handle, path, watcher, callback)
223 self._check_result(result, d)225 self._check_result(result, d, path=path)
224 return d226 return d
225227
226 def _get_children(self, path, watcher):228 def _get_children(self, path, watcher):
@@ -229,14 +231,14 @@
229 return d231 return d
230232
231 def _cb_get_children(result_code, children):233 def _cb_get_children(result_code, children):
232 if self._check_result(result_code, d):234 if self._check_result(result_code, d, path=path):
233 return235 return
234 d.callback(children)236 d.callback(children)
235237
236 callback = self._zk_thread_callback(_cb_get_children)238 callback = self._zk_thread_callback(_cb_get_children)
237 watcher = self._wrap_watcher(watcher)239 watcher = self._wrap_watcher(watcher)
238 result = zookeeper.aget_children(self.handle, path, watcher, callback)240 result = zookeeper.aget_children(self.handle, path, watcher, callback)
239 self._check_result(result, d)241 self._check_result(result, d, path=path)
240 return d242 return d
241243
242 def _exists(self, path, watcher):244 def _exists(self, path, watcher):
@@ -246,14 +248,14 @@
246248
247 def _cb_exists(result_code, stat):249 def _cb_exists(result_code, stat):
248 if self._check_result(250 if self._check_result(
249 result_code, d, extra_codes=(zookeeper.NONODE,)):251 result_code, d, extra_codes=(zookeeper.NONODE,), path=path):
250 return252 return
251 d.callback(stat)253 d.callback(stat)
252254
253 callback = self._zk_thread_callback(_cb_exists)255 callback = self._zk_thread_callback(_cb_exists)
254 watcher = self._wrap_watcher(watcher)256 watcher = self._wrap_watcher(watcher)
255 result = zookeeper.aexists(self.handle, path, watcher, callback)257 result = zookeeper.aexists(self.handle, path, watcher, callback)
256 self._check_result(result, d)258 self._check_result(result, d, path=path)
257 return d259 return d
258260
259 def _wrap_watcher(self, watcher):261 def _wrap_watcher(self, watcher):
@@ -489,14 +491,14 @@
489 return d491 return d
490492
491 def _cb_created(result_code, path):493 def _cb_created(result_code, path):
492 if self._check_result(result_code, d):494 if self._check_result(result_code, d, path=path):
493 return495 return
494 d.callback(path)496 d.callback(path)
495497
496 callback = self._zk_thread_callback(_cb_created)498 callback = self._zk_thread_callback(_cb_created)
497 result = zookeeper.acreate(499 result = zookeeper.acreate(
498 self.handle, path, data, acls, flags, callback)500 self.handle, path, data, acls, flags, callback)
499 self._check_result(result, d)501 self._check_result(result, d, path=path)
500 return d502 return d
501503
502 def delete(self, path, version=-1):504 def delete(self, path, version=-1):
@@ -514,13 +516,13 @@
514 return d516 return d
515517
516 def _cb_delete(result_code):518 def _cb_delete(result_code):
517 if self._check_result(result_code, d):519 if self._check_result(result_code, d, path=path):
518 return520 return
519 d.callback(result_code)521 d.callback(result_code)
520522
521 callback = self._zk_thread_callback(_cb_delete)523 callback = self._zk_thread_callback(_cb_delete)
522 result = zookeeper.adelete(self.handle, path, version, callback)524 result = zookeeper.adelete(self.handle, path, version, callback)
523 self._check_result(result, d)525 self._check_result(result, d, path=path)
524 return d526 return d
525527
526 def exists(self, path):528 def exists(self, path):
@@ -621,13 +623,13 @@
621 return d623 return d
622624
623 def _cb_get_acl(result_code, acls, stat):625 def _cb_get_acl(result_code, acls, stat):
624 if self._check_result(result_code, d):626 if self._check_result(result_code, d, path=path):
625 return627 return
626 d.callback((acls, stat))628 d.callback((acls, stat))
627629
628 callback = self._zk_thread_callback(_cb_get_acl)630 callback = self._zk_thread_callback(_cb_get_acl)
629 result = zookeeper.aget_acl(self.handle, path, callback)631 result = zookeeper.aget_acl(self.handle, path, callback)
630 self._check_result(result, d)632 self._check_result(result, d, path=path)
631 return d633 return d
632634
633 def set_acl(self, path, acls, version=-1):635 def set_acl(self, path, acls, version=-1):
@@ -665,7 +667,7 @@
665 callback = self._zk_thread_callback(_cb_set_acl)667 callback = self._zk_thread_callback(_cb_set_acl)
666 result = zookeeper.aset_acl(668 result = zookeeper.aset_acl(
667 self.handle, path, version, acls, callback)669 self.handle, path, version, acls, callback)
668 self._check_result(result, d)670 self._check_result(result, d, path=path)
669 return d671 return d
670672
671 def set(self, path, data="", version=-1):673 def set(self, path, data="", version=-1):
@@ -684,13 +686,13 @@
684 return d686 return d
685687
686 def _cb_set(result_code, node_stat):688 def _cb_set(result_code, node_stat):
687 if self._check_result(result_code, d):689 if self._check_result(result_code, d, path=path):
688 return690 return
689 d.callback(node_stat)691 d.callback(node_stat)
690692
691 callback = self._zk_thread_callback(_cb_set)693 callback = self._zk_thread_callback(_cb_set)
692 result = zookeeper.aset(self.handle, path, data, version, callback)694 result = zookeeper.aset(self.handle, path, data, version, callback)
693 self._check_result(result, d)695 self._check_result(result, d, path=path)
694 return d696 return d
695697
696 def set_connection_watcher(self, watcher):698 def set_connection_watcher(self, watcher):
@@ -761,11 +763,11 @@
761 return d763 return d
762764
763 def _cb_sync(result_code, path):765 def _cb_sync(result_code, path):
764 if self._check_result(result_code, d):766 if self._check_result(result_code, d, path=path):
765 return767 return
766 d.callback(path)768 d.callback(path)
767769
768 callback = self._zk_thread_callback(_cb_sync)770 callback = self._zk_thread_callback(_cb_sync)
769 result = zookeeper.async(self.handle, path, callback)771 result = zookeeper.async(self.handle, path, callback)
770 self._check_result(result, d)772 self._check_result(result, d, path=path)
771 return d773 return d

Subscribers

People subscribed via source and target branches

to all changes: