Use libvirt error message for python exceptions

This commit is contained in:
Daniel P. Berrange 2008-08-22 10:50:18 +00:00
parent 6c02ba0540
commit 8f789f1b2f
2 changed files with 16 additions and 10 deletions

View File

@ -1,3 +1,8 @@
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

View File

@ -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:
self.err = conn.virConnGetLastError()
err = conn.virConnGetLastError()
if err is None:
msg = defmsg
else:
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
#