# HG changeset patch
# User emellor@ewan
# Node ID 79f695037ab7912b0e8690bff3e64a264f8d323d
# Parent ba10ee566ab7551b3a0257ffe0d00e11ae8649b4
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@xxxxxxxxxxxxx>
diff -r ba10ee566ab7 -r 79f695037ab7
tools/python/xen/xend/xenstore/xstransact.py
--- a/tools/python/xen/xend/xenstore/xstransact.py Wed Sep 21 10:26:31 2005
+++ b/tools/python/xen/xend/xenstore/xstransact.py Wed Sep 21 10:29:23 2005
@@ -41,7 +41,11 @@
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 @@
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 @@
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]
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|