summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libvir.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/libvir.py b/libvir.py
index 784152a..cf5e776 100644
--- a/libvir.py
+++ b/libvir.py
@@ -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
#