From a12e799bd326e0b745a50401e0f4d5336d89fb34 Mon Sep 17 00:00:00 2001 From: dgw Date: Thu, 21 Sep 2023 01:52:22 -0500 Subject: [PATCH] calc: gracefully handle `ExpressionEvaluator.Error` We might consider making this exception a standalone class, for less wacky-looking error handling in this and other consumers of the `tools.calculation` submodule. Doing `except a_function.Subclass` feels weird and wrong. --- sopel/modules/calc.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sopel/modules/calc.py b/sopel/modules/calc.py index 2c87bb217c..f591a3ab01 100644 --- a/sopel/modules/calc.py +++ b/sopel/modules/calc.py @@ -30,6 +30,9 @@ def c(bot, trigger): try: result = eval_equation(eqn) result = "{:.10g}".format(result) + except eval_equation.Error as err: + bot.reply("Can't process expression: {}".format(str(err))) + return except ZeroDivisionError: bot.reply('Division by zero is not supported in this universe.') return