Added diagnostic messages to the RuntimeError exceptions when they occur inside

_read and _write.  Fix gather to not return the string 'None' when reading a
value of type string that does not exist.  The value None should be returned
instead.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
emellor@ewan committed 2005-09-21 11:29:23 +01:00
1 parent 57ff2ac70a
commit df0fc046af
1 file changed
+24 -5
+24 -5
View File
@@ -41,7 +41,11 @@ class xstransact:
def _read(self, key):
path = "%s/%s" % (self.path, key)
return xshandle().read(path)
try:
return xshandle().read(path)
except RuntimeError, ex:
raise RuntimeError(ex.args[0],
'%s, while reading %s' % (ex.args[1], path))
def read(self, *args):
if len(args) == 0:
@@ -55,7 +59,12 @@ class xstransact:
def _write(self, key, data):
path = "%s/%s" % (self.path, key)
xshandle().write(path, data)
try:
xshandle().write(path, data)
except RuntimeError, ex:
raise RuntimeError(ex.args[0],
('%s, while writing %s : %s' %
(ex.args[1], path, str(data))))
def write(self, *args, **opts):
if len(args) == 0:
@@ -121,10 +130,20 @@ class xstransact:
defval = None
else:
(key, fn, defval) = tup
try:
val = fn(self._read(key))
except TypeError:
val = self._read(key)
# If fn is str, then this will successfully convert None to
# 'None'. If it is int, then it will throw TypeError on None, or
# on any other non-integer value. We have to, therefore, both
# check explicitly for None, and catch TypeError. Either failure
# will result in defval being used instead.
if val is None:
val = defval
else:
try:
val = fn(val)
except TypeError:
val = defval
ret.append(val)
if len(ret) == 1:
return ret[0]
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.