mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-08-04 12:21:57 +03:00
stream: Fix exception traceback handling
sys.exc_info() returns a 3-tuple (type, value, traceback). Raising just `value` again looses the traceback information as this creates a new exception. Just use `raise` which re-raises the previous exception including the original traceback. FYI: There is a subtile difference between Python 2 and Python 3: > try: > raise ValueError() > except ValueError: > try: > raise TypeError() > except TypeError: > pass > raise With Python 3 the exception environment is dropped after the exception has been handled - as such Python 3 re-raises the outer ValueError. With Python 2 the last (inner) exception is raised: TypeError Signed-off-by: Philipp Hahn <hahn@univention.de>
This commit is contained in:
committed by
Daniel Berrange
parent
9074b50259
commit
06222739f7
@ -52,12 +52,11 @@
|
||||
if type(ret) is int and ret < 0:
|
||||
raise RuntimeError("recvAll handler returned %d" % ret)
|
||||
except BaseException:
|
||||
e = sys.exc_info()[1]
|
||||
try:
|
||||
self.abort()
|
||||
except Exception:
|
||||
pass
|
||||
raise e
|
||||
raise
|
||||
|
||||
def sendAll(self, handler: Callable[['virStream', int, _T], bytes], opaque: _T) -> None:
|
||||
"""
|
||||
@ -77,12 +76,11 @@
|
||||
try:
|
||||
got = handler(self, virStorageVol.streamBufSize, opaque)
|
||||
except BaseException:
|
||||
e = sys.exc_info()[1]
|
||||
try:
|
||||
self.abort()
|
||||
except Exception:
|
||||
pass
|
||||
raise e
|
||||
raise
|
||||
|
||||
if not got:
|
||||
break
|
||||
|
Reference in New Issue
Block a user