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

Proposed by Kapil Thangavelu
Status: Merged
Approved by: Jim Baker
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
Gustavo Niemeyer Approve
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.
Revision history for this message
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
Revision history for this message
Jim Baker (jimbaker) wrote :

+1, simple change and does provide useful info

review: Approve
45. By Kapil Thangavelu

merge trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txzookeeper/client.py'
2--- txzookeeper/client.py 2011-12-06 21:21:29 +0000
3+++ txzookeeper/client.py 2012-02-03 15:13:22 +0000
4@@ -174,7 +174,7 @@
5 d.errback(NotConnectedException("not connected"))
6 return d
7
8- def _check_result(self, result_code, deferred, extra_codes=()):
9+ def _check_result(self, result_code, deferred, extra_codes=(), path=None):
10 """Check an API call or result for errors.
11
12 :param result_code: The api result code.
13@@ -187,6 +187,8 @@
14 error = None
15 if not result_code == zookeeper.OK and not result_code in extra_codes:
16 error_msg = zookeeper.zerror(result_code)
17+ if path is not None:
18+ error_msg += " %s" % path
19 error_class = ERROR_MAPPING.get(
20 result_code, zookeeper.ZooKeeperException)
21 error = error_class(error_msg)
22@@ -213,14 +215,14 @@
23 return d
24
25 def _cb_get(result_code, value, stat):
26- if self._check_result(result_code, d):
27+ if self._check_result(result_code, d, path=path):
28 return
29 d.callback((value, stat))
30
31 callback = self._zk_thread_callback(_cb_get)
32 watcher = self._wrap_watcher(watcher)
33 result = zookeeper.aget(self.handle, path, watcher, callback)
34- self._check_result(result, d)
35+ self._check_result(result, d, path=path)
36 return d
37
38 def _get_children(self, path, watcher):
39@@ -229,14 +231,14 @@
40 return d
41
42 def _cb_get_children(result_code, children):
43- if self._check_result(result_code, d):
44+ if self._check_result(result_code, d, path=path):
45 return
46 d.callback(children)
47
48 callback = self._zk_thread_callback(_cb_get_children)
49 watcher = self._wrap_watcher(watcher)
50 result = zookeeper.aget_children(self.handle, path, watcher, callback)
51- self._check_result(result, d)
52+ self._check_result(result, d, path=path)
53 return d
54
55 def _exists(self, path, watcher):
56@@ -246,14 +248,14 @@
57
58 def _cb_exists(result_code, stat):
59 if self._check_result(
60- result_code, d, extra_codes=(zookeeper.NONODE,)):
61+ result_code, d, extra_codes=(zookeeper.NONODE,), path=path):
62 return
63 d.callback(stat)
64
65 callback = self._zk_thread_callback(_cb_exists)
66 watcher = self._wrap_watcher(watcher)
67 result = zookeeper.aexists(self.handle, path, watcher, callback)
68- self._check_result(result, d)
69+ self._check_result(result, d, path=path)
70 return d
71
72 def _wrap_watcher(self, watcher):
73@@ -489,14 +491,14 @@
74 return d
75
76 def _cb_created(result_code, path):
77- if self._check_result(result_code, d):
78+ if self._check_result(result_code, d, path=path):
79 return
80 d.callback(path)
81
82 callback = self._zk_thread_callback(_cb_created)
83 result = zookeeper.acreate(
84 self.handle, path, data, acls, flags, callback)
85- self._check_result(result, d)
86+ self._check_result(result, d, path=path)
87 return d
88
89 def delete(self, path, version=-1):
90@@ -514,13 +516,13 @@
91 return d
92
93 def _cb_delete(result_code):
94- if self._check_result(result_code, d):
95+ if self._check_result(result_code, d, path=path):
96 return
97 d.callback(result_code)
98
99 callback = self._zk_thread_callback(_cb_delete)
100 result = zookeeper.adelete(self.handle, path, version, callback)
101- self._check_result(result, d)
102+ self._check_result(result, d, path=path)
103 return d
104
105 def exists(self, path):
106@@ -621,13 +623,13 @@
107 return d
108
109 def _cb_get_acl(result_code, acls, stat):
110- if self._check_result(result_code, d):
111+ if self._check_result(result_code, d, path=path):
112 return
113 d.callback((acls, stat))
114
115 callback = self._zk_thread_callback(_cb_get_acl)
116 result = zookeeper.aget_acl(self.handle, path, callback)
117- self._check_result(result, d)
118+ self._check_result(result, d, path=path)
119 return d
120
121 def set_acl(self, path, acls, version=-1):
122@@ -665,7 +667,7 @@
123 callback = self._zk_thread_callback(_cb_set_acl)
124 result = zookeeper.aset_acl(
125 self.handle, path, version, acls, callback)
126- self._check_result(result, d)
127+ self._check_result(result, d, path=path)
128 return d
129
130 def set(self, path, data="", version=-1):
131@@ -684,13 +686,13 @@
132 return d
133
134 def _cb_set(result_code, node_stat):
135- if self._check_result(result_code, d):
136+ if self._check_result(result_code, d, path=path):
137 return
138 d.callback(node_stat)
139
140 callback = self._zk_thread_callback(_cb_set)
141 result = zookeeper.aset(self.handle, path, data, version, callback)
142- self._check_result(result, d)
143+ self._check_result(result, d, path=path)
144 return d
145
146 def set_connection_watcher(self, watcher):
147@@ -761,11 +763,11 @@
148 return d
149
150 def _cb_sync(result_code, path):
151- if self._check_result(result_code, d):
152+ if self._check_result(result_code, d, path=path):
153 return
154 d.callback(path)
155
156 callback = self._zk_thread_callback(_cb_sync)
157 result = zookeeper.async(self.handle, path, callback)
158- self._check_result(result, d)
159+ self._check_result(result, d, path=path)
160 return d

Subscribers

People subscribed via source and target branches

to all changes: