aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/events.py9
-rw-r--r--bot/cogs/tags.py17
-rw-r--r--bot/exceptions.py10
3 files changed, 14 insertions, 22 deletions
diff --git a/bot/cogs/events.py b/bot/cogs/events.py
index 34ceeb399..9375c348f 100644
--- a/bot/cogs/events.py
+++ b/bot/cogs/events.py
@@ -8,7 +8,6 @@ from discord.ext.commands import (
)
from bot.constants import DEVLOG_CHANNEL, PYTHON_GUILD, SITE_API_KEY, SITE_API_USER_URL
-from bot.exceptions import CogBadArgument
from bot.utils import chunks
log = logging.getLogger(__name__)
@@ -49,9 +48,11 @@ class Events:
else:
help_command = (self.bot.get_command("help"),)
- if isinstance(e, CogBadArgument):
- log.debug(f"Command {command} raised `CogBadArgument`, ignoring.")
- elif isinstance(e, BadArgument):
+ if hasattr(command, "error"):
+ log.debug(f"Command {command} has a local error handler, ignoring.")
+ return
+
+ if isinstance(e, BadArgument):
await ctx.send(f"Bad argument: {e}\n")
await ctx.invoke(*help_command)
elif isinstance(e, UserInputError):
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py
index a7c6b0248..a834d5327 100644
--- a/bot/cogs/tags.py
+++ b/bot/cogs/tags.py
@@ -4,7 +4,7 @@ import time
from discord import Colour, Embed
from discord.ext.commands import (
- AutoShardedBot, Context,
+ AutoShardedBot, BadArgument, Context,
Converter, command
)
@@ -14,7 +14,6 @@ from bot.constants import (
SITE_API_KEY, SITE_API_TAGS_URL, TAG_COOLDOWN
)
from bot.decorators import with_role
-from bot.exceptions import CogBadArgument
from bot.pagination import LinePaginator
log = logging.getLogger(__name__)
@@ -42,25 +41,25 @@ class TagNameConverter(Converter):
if ascii(tag_name)[1:-1] != tag_name:
log.warning(f"{ctx.author} tried to put an invalid character in a tag name. "
"Rejecting the request.")
- raise CogBadArgument("Don't be ridiculous, you can't use that character!")
+ raise BadArgument("Don't be ridiculous, you can't use that character!")
# The tag name is either empty, or consists of nothing but whitespace.
elif not tag_name:
log.warning(f"{ctx.author} tried to create a tag with a name consisting only of whitespace. "
"Rejecting the request.")
- raise CogBadArgument("Tag names should not be empty, or filled with whitespace.")
+ raise BadArgument("Tag names should not be empty, or filled with whitespace.")
# The tag name is a number of some kind, we don't allow that.
elif is_number(tag_name):
log.warning(f"{ctx.author} tried to create a tag with a digit as its name. "
"Rejecting the request.")
- raise CogBadArgument("Tag names can't be numbers.")
+ raise BadArgument("Tag names can't be numbers.")
# The tag name is longer than 127 characters.
elif len(tag_name) > 127:
log.warning(f"{ctx.author} tried to request a tag name with over 127 characters. "
"Rejecting the request.")
- raise CogBadArgument("Are you insane? That's way too long!")
+ raise BadArgument("Are you insane? That's way too long!")
return tag_name
@@ -74,7 +73,7 @@ class TagContentConverter(Converter):
if not tag_content:
log.warning(f"{ctx.author} tried to create a tag containing only whitespace. "
"Rejecting the request.")
- raise CogBadArgument("Tag contents should not be empty, or filled with whitespace.")
+ raise BadArgument("Tag contents should not be empty, or filled with whitespace.")
return tag_content
@@ -346,12 +345,14 @@ class Tags:
@set_command.error
@delete_command.error
async def command_error(self, ctx, error):
- if isinstance(error, CogBadArgument):
+ if isinstance(error, BadArgument):
embed = Embed()
embed.colour = Colour.red()
embed.description = str(error)
embed.title = random.choice(self.FAIL_TITLES)
await ctx.send(embed=embed)
+ else:
+ log.error(f"Unhandled tag command error: {error} ({error.original})")
@command(name="tags.keys()")
async def keys_command(self, ctx: Context):
diff --git a/bot/exceptions.py b/bot/exceptions.py
deleted file mode 100644
index 8f5da91e9..000000000
--- a/bot/exceptions.py
+++ /dev/null
@@ -1,10 +0,0 @@
-from discord.ext.commands import BadArgument
-
-
-class CogBadArgument(BadArgument):
- """
- A custom `BadArgument` subclass that can be used for
- setting up custom error handlers on a per-command
- basis in cogs. The standard `on_command_error` handler
- ignores any exceptions of this type.
- """