summaryrefslogtreecommitdiff
path: root/libvirt-override-virStream.py
diff options
context:
space:
mode:
authorPhilipp Hahn <hahn@univention.de>2020-04-27 10:54:33 +0200
committerDaniel Berrange <berrange@redhat.com>2020-08-18 09:48:25 +0000
commit06222739f7dd332f77744a5ddf2883624747dfa3 (patch)
tree468613af64d758ea4c0182fc80382b01bfd82a45 /libvirt-override-virStream.py
parent9074b502598949bffac8ce0c5b7a04b38a5c523c (diff)
downloadlibvirt-python-06222739f7dd332f77744a5ddf2883624747dfa3.tar.gz
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>
Diffstat (limited to 'libvirt-override-virStream.py')
-rw-r--r--libvirt-override-virStream.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/libvirt-override-virStream.py b/libvirt-override-virStream.py
index 998ad41..2d716eb 100644
--- a/libvirt-override-virStream.py
+++ b/libvirt-override-virStream.py
@@ -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