Skip to content

Commit

Permalink
[calc] Add guards to pow and mul functions to avoid hangs.
Browse files Browse the repository at this point in the history
- Fixes sopel-irc#538.

- Removed the drivel from calc when exceptions are raised. Printing the actual
  error might not be pretty, but at least it's not completely useless.
  • Loading branch information
ari-koivula committed Jul 7, 2014
1 parent b549625 commit 899d2b7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@commands('c', 'calc')
@example('.c 5 + 3', '8')
def c(bot, trigger):
"""Google calculator."""
"""Evaluate some calculation."""
if not trigger.group(2):
return bot.reply("Nothing to calculate.")
# Account for the silly non-Anglophones and their silly radix point.
Expand All @@ -32,10 +32,9 @@ def c(bot, trigger):
result = str(eval_equation(eqn))
except ZeroDivisionError:
result = "Division by zero is not supported in this universe."
except Exception:
result = ("Sorry, I can't calculate that with this command. "
"I might have another one that can. "
"Use .commands for a list.")
except Exception as e:
result = "{error}: {msg}".format(
error=type(e), msg=e)
bot.reply(result)


Expand Down

0 comments on commit 899d2b7

Please sign in to comment.