From 06222739f7dd332f77744a5ddf2883624747dfa3 Mon Sep 17 00:00:00 2001 From: Philipp Hahn Date: Mon, 27 Apr 2020 10:54:33 +0200 Subject: 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 --- libvirt-override-virStream.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'libvirt-override-virStream.py') 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 -- cgit v1.2.1