mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Use libvirt error message for python exceptions
This commit is contained in:
@@ -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>
|
Fri Aug 22 10:30:42 CEST 2008 Jim Meyering <meyering@redhat.com>
|
||||||
|
|
||||||
configure.in: link with -lpthread when necessary
|
configure.in: link with -lpthread when necessary
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ import types
|
|||||||
|
|
||||||
# The root of all libvirt errors.
|
# The root of all libvirt errors.
|
||||||
class libvirtError(Exception):
|
class libvirtError(Exception):
|
||||||
def __init__(self, msg, conn=None, dom=None, net=None, pool=None, vol=None):
|
def __init__(self, defmsg, conn=None, dom=None, net=None, pool=None, vol=None):
|
||||||
Exception.__init__(self, msg)
|
|
||||||
|
|
||||||
if dom is not None:
|
if dom is not None:
|
||||||
conn = dom._conn
|
conn = dom._conn
|
||||||
@@ -28,9 +27,17 @@ class libvirtError(Exception):
|
|||||||
conn = vol._conn
|
conn = vol._conn
|
||||||
|
|
||||||
if conn is None:
|
if conn is None:
|
||||||
self.err = virGetLastError()
|
err = virGetLastError()
|
||||||
else:
|
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):
|
def get_error_code(self):
|
||||||
if self.err is None:
|
if self.err is None:
|
||||||
@@ -77,12 +84,6 @@ class libvirtError(Exception):
|
|||||||
return None
|
return None
|
||||||
return self.err[8]
|
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
|
# register the libvirt global error handler
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user