From d7184e422d5d43d72cd7430d7cd834cfbde1b43b Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Tue, 10 Jul 2018 22:19:41 +0200 Subject: [PATCH] Add PySnmpError.cause attribute To convey parent exception information on re-raise --- CHANGES.txt | 1 + pysnmp/error.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index be7ab3a85..2729be800 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,7 @@ Revision 4.4.5, released 2018-04-XX ----------------------------------- +- Added PySnmpError.cause attribute holding parent exception tuple - Fixed broken InetAddressType rendering caused by a pyasn1 regression - Fixed typo in RFC1158 module - Fixed possible infinite loop in GETBULK response PDU builder diff --git a/pysnmp/error.py b/pysnmp/error.py index 3f546c79b..b5bb35b51 100644 --- a/pysnmp/error.py +++ b/pysnmp/error.py @@ -5,6 +5,10 @@ # License: http://snmplabs.com/pysnmp/license.html # +import sys + class PySnmpError(Exception): - pass + def __init__(self, message): + self.cause = sys.exc_info() + Exception.__init__(self, '%s, caused by %s: %s' % (message, self.cause[0], self.cause[1]))