Math: Display a nicer error in case of MemoryError.

This commit is contained in:
Valentin Lorentz 2019-11-11 12:12:10 +01:00
parent 2dddfefa98
commit 78a50c81bd
2 changed files with 5 additions and 0 deletions

View File

@ -149,6 +149,8 @@ class Math(callbacks.Plugin):
irc.error(_('Invalid syntax: %s') % e.args[0])
except NameError as e:
irc.error(_('%s is not a defined function.') % e.args[0])
except MemoryError:
irc.error(_('Memory error (too much recursion?)'))
except Exception as e:
irc.error(str(e))
calc = wrap(calc, ['text'])

View File

@ -135,6 +135,9 @@ class MathTestCase(PluginTestCase):
def testCalcStrFloat(self):
self.assertResponse('calc 3+33333333333333', '33333333333336')
def testCalcMemoryError(self):
self.assertRegexp('calc ' + '('*500, 'too much recursion')
def testICalc(self):
self.assertResponse('icalc 1^1', '0')
self.assertResponse('icalc 10**24', '1' + '0'*24)