提交 8f789f1b 编写于 作者: D Daniel P. Berrange

Use libvirt error message for python exceptions

上级 6c02ba05
Fri Aug 22 11:49:42 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* python/libvir.py: Use libvirt error message as exception
message for improved diagnostics
Fri Aug 22 10:30:42 CEST 2008 Jim Meyering <meyering@redhat.com>
configure.in: link with -lpthread when necessary
......
......@@ -15,8 +15,7 @@ import types
# The root of all libvirt errors.
class libvirtError(Exception):
def __init__(self, msg, conn=None, dom=None, net=None, pool=None, vol=None):
Exception.__init__(self, msg)
def __init__(self, defmsg, conn=None, dom=None, net=None, pool=None, vol=None):
if dom is not None:
conn = dom._conn
......@@ -28,9 +27,17 @@ class libvirtError(Exception):
conn = vol._conn
if conn is None:
self.err = virGetLastError()
err = virGetLastError()
else:
err = conn.virConnGetLastError()
if err is None:
msg = defmsg
else:
self.err = conn.virConnGetLastError()
msg = err[2]
Exception.__init__(self, msg)
self.err = err
def get_error_code(self):
if self.err is None:
......@@ -77,12 +84,6 @@ class libvirtError(Exception):
return None
return self.err[8]
def __str__(self):
if self.get_error_message() is None:
return Exception.__str__(self)
else:
return Exception.__str__(self) + " " + self.get_error_message()
#
# register the libvirt global error handler
#
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册