Skip to content

Commit

Permalink
dice: catch ValueError from too-large integer conversion
Browse files Browse the repository at this point in the history
A selection of rolled dice can pass the equation evaluator's complexity
checks but still yield a result that's too large for `str` conversion.

https://docs.python.org/3.12/library/stdtypes.html#int-max-str-digits
  • Loading branch information
dgw committed Oct 26, 2023
1 parent 06f3fd2 commit 543b423
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sopel/modules/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,10 @@ def _get_pretty_str(dice):
)
return

bot.say("%s: %s = %d" % (arg_str_raw, pretty_str, result))
try:
bot.say("%s: %s = %d" % (arg_str_raw, pretty_str, result))
except ValueError:
# Converting the result to a string can also raise ValueError if it has
# more than int_max_str_digits digits (4300 by default on CPython)
# See https://docs.python.org/3.12/library/stdtypes.html#int-max-str-digits
bot.reply("I can't display a number that big. =(")

0 comments on commit 543b423

Please sign in to comment.