From 012d99c05cb0c706e2d1a4a2782ae60cceea906d Mon Sep 17 00:00:00 2001 From: Michael H Date: Mon, 22 Apr 2019 22:34:38 -0400 Subject: [PATCH] [Utils] Better error handling for humanize_list (#2597) --- redbot/core/utils/chat_formatting.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/redbot/core/utils/chat_formatting.py b/redbot/core/utils/chat_formatting.py index 23d4a5e4e..5168a2cd6 100644 --- a/redbot/core/utils/chat_formatting.py +++ b/redbot/core/utils/chat_formatting.py @@ -360,7 +360,10 @@ def humanize_list(items: Sequence[str]) -> str: """ if len(items) == 1: return items[0] - return ", ".join(items[:-1]) + _(", and ") + items[-1] + try: + return ", ".join(items[:-1]) + _(", and ") + items[-1] + except IndexError: + raise IndexError("Cannot humanize empty sequence") from None def format_perms_list(perms: discord.Permissions) -> str: