From 543b4235242f1eec0c46f2697dca3d88b947832d Mon Sep 17 00:00:00 2001 From: dgw Date: Thu, 26 Oct 2023 05:45:59 -0500 Subject: [PATCH] dice: catch `ValueError` from too-large integer conversion 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 --- sopel/modules/dice.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sopel/modules/dice.py b/sopel/modules/dice.py index 7c72113c6..7a9456074 100644 --- a/sopel/modules/dice.py +++ b/sopel/modules/dice.py @@ -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. =(")