diff --git a/src/utils.py b/src/utils.py index 713f0c8ed..17ff1b8fa 100755 --- a/src/utils.py +++ b/src/utils.py @@ -537,7 +537,11 @@ def safeEval(s, namespace={'True': True, 'False': False, 'None': None}): def exnToString(e): """Turns a simple exception instance into a string (better than str(e))""" - return '%s: %s' % (e.__class__.__name__, e) + strE = str(e) + if strE: + return '%s: %s' % (e.__class__.__name__, strE) + else: + return e.__class__.__name__ class IterableMap(object): """Define .iteritems() in a class and subclass this to get the other iters. diff --git a/test/test_utils.py b/test/test_utils.py index aa3744a12..74e487695 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -33,6 +33,16 @@ import sets import supybot.utils as utils class UtilsTest(SupyTestCase): + def testExnToString(self): + try: + raise KeyError, 1 + except Exception, e: + self.assertEqual(utils.exnToString(e), 'KeyError: 1') + try: + raise EOFError + except Exception, e: + self.assertEqual(utils.exnToString(e), 'EOFError') + def testMatchCase(self): f = utils.matchCase self.assertEqual('bar', f('foo', 'bar'))