From 3b514f9aec31723587caa1475d38d836bf300563 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Sun, 5 Aug 2018 10:24:50 +0200 Subject: Fix PySnmpError implementation This is a follow up fix to make PySnmpError properly overriding base Exception call signature --- pysnmp/error.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'pysnmp') diff --git a/pysnmp/error.py b/pysnmp/error.py index b5bb35b5..e47f4bcb 100644 --- a/pysnmp/error.py +++ b/pysnmp/error.py @@ -9,6 +9,15 @@ import sys class PySnmpError(Exception): - def __init__(self, message): + def __init__(self, *args): + msg = args and str(args[0]) or '' + self.cause = sys.exc_info() - Exception.__init__(self, '%s, caused by %s: %s' % (message, self.cause[0], self.cause[1])) + + if self.cause[0]: + msg += 'caused by %s: %s' % (self.cause[0], self.cause[1]) + + if msg: + args = (msg,) + args[1:] + + Exception.__init__(self, *args) -- cgit v1.2.1