aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar wookie184 <[email protected]>2021-10-17 10:55:14 +0100
committerGravatar GitHub <[email protected]>2021-10-17 09:55:14 +0000
commit77e83e01c3adbce4bd9ffac4eeb031cf8a283640 (patch)
tree6b8c416b1eafa23fa9f61384728346e15b8fe58c
parentRegex: add a word boundary before .gg (#1817) (diff)
Fixed delayed logs and made some other minor refactors (#1863)
* Run debug log before help command invocation to avoid delayed logs * Refactored other areas of code slightly, ensuring logging is done as soon as possible. Removed outdated comment * Ensured debug logs were sent for disabled commands Co-authored-by: Xithrius <[email protected]>
-rw-r--r--bot/exts/backend/error_handler.py47
1 files changed, 19 insertions, 28 deletions
diff --git a/bot/exts/backend/error_handler.py b/bot/exts/backend/error_handler.py
index 7644b93ae..6ab6634a6 100644
--- a/bot/exts/backend/error_handler.py
+++ b/bot/exts/backend/error_handler.py
@@ -59,17 +59,23 @@ class ErrorHandler(Cog):
log.trace(f"Command {command} had its error already handled locally; ignoring.")
return
+ debug_message = (
+ f"Command {command} invoked by {ctx.message.author} with error "
+ f"{e.__class__.__name__}: {e}"
+ )
+
if isinstance(e, errors.CommandNotFound) and not getattr(ctx, "invoked_from_error_handler", False):
if await self.try_silence(ctx):
return
- # Try to look for a tag with the command's name
- await self.try_get_tag(ctx)
- return # Exit early to avoid logging.
+ await self.try_get_tag(ctx) # Try to look for a tag with the command's name
elif isinstance(e, errors.UserInputError):
+ log.debug(debug_message)
await self.handle_user_input_error(ctx, e)
elif isinstance(e, errors.CheckFailure):
+ log.debug(debug_message)
await self.handle_check_failure(ctx, e)
elif isinstance(e, errors.CommandOnCooldown):
+ log.debug(debug_message)
await ctx.send(e)
elif isinstance(e, errors.CommandInvokeError):
if isinstance(e.original, ResponseCodeError):
@@ -80,22 +86,16 @@ class ErrorHandler(Cog):
await ctx.send(f"Cannot infract that user. {e.original.reason}")
else:
await self.handle_unexpected_error(ctx, e.original)
- return # Exit early to avoid logging.
elif isinstance(e, errors.ConversionError):
if isinstance(e.original, ResponseCodeError):
await self.handle_api_error(ctx, e.original)
else:
await self.handle_unexpected_error(ctx, e.original)
- return # Exit early to avoid logging.
- elif not isinstance(e, errors.DisabledCommand):
+ elif isinstance(e, errors.DisabledCommand):
+ log.debug(debug_message)
+ else:
# MaxConcurrencyReached, ExtensionError
await self.handle_unexpected_error(ctx, e)
- return # Exit early to avoid logging.
-
- log.debug(
- f"Command {command} invoked by {ctx.message.author} with error "
- f"{e.__class__.__name__}: {e}"
- )
@staticmethod
def get_help_command(ctx: Context) -> t.Coroutine:
@@ -188,9 +188,6 @@ class ErrorHandler(Cog):
if not any(role.id in MODERATION_ROLES for role in ctx.author.roles):
await self.send_command_suggestion(ctx, ctx.invoked_with)
- # Return to not raise the exception
- return
-
async def send_command_suggestion(self, ctx: Context, command_name: str) -> None:
"""Sends user similar commands if any can be found."""
# No similar tag found, or tag on cooldown -
@@ -235,38 +232,32 @@ class ErrorHandler(Cog):
"""
if isinstance(e, errors.MissingRequiredArgument):
embed = self._get_error_embed("Missing required argument", e.param.name)
- await ctx.send(embed=embed)
- await self.get_help_command(ctx)
self.bot.stats.incr("errors.missing_required_argument")
elif isinstance(e, errors.TooManyArguments):
embed = self._get_error_embed("Too many arguments", str(e))
- await ctx.send(embed=embed)
- await self.get_help_command(ctx)
self.bot.stats.incr("errors.too_many_arguments")
elif isinstance(e, errors.BadArgument):
embed = self._get_error_embed("Bad argument", str(e))
- await ctx.send(embed=embed)
- await self.get_help_command(ctx)
self.bot.stats.incr("errors.bad_argument")
elif isinstance(e, errors.BadUnionArgument):
embed = self._get_error_embed("Bad argument", f"{e}\n{e.errors[-1]}")
- await ctx.send(embed=embed)
- await self.get_help_command(ctx)
self.bot.stats.incr("errors.bad_union_argument")
elif isinstance(e, errors.ArgumentParsingError):
embed = self._get_error_embed("Argument parsing error", str(e))
await ctx.send(embed=embed)
self.get_help_command(ctx).close()
self.bot.stats.incr("errors.argument_parsing_error")
+ return
else:
embed = self._get_error_embed(
"Input error",
"Something about your input seems off. Check the arguments and try again."
)
- await ctx.send(embed=embed)
- await self.get_help_command(ctx)
self.bot.stats.incr("errors.other_user_input_error")
+ await ctx.send(embed=embed)
+ await self.get_help_command(ctx)
+
@staticmethod
async def handle_check_failure(ctx: Context, e: errors.CheckFailure) -> None:
"""
@@ -299,8 +290,8 @@ class ErrorHandler(Cog):
async def handle_api_error(ctx: Context, e: ResponseCodeError) -> None:
"""Send an error message in `ctx` for ResponseCodeError and log it."""
if e.status == 404:
- await ctx.send("There does not seem to be anything matching your query.")
log.debug(f"API responded with 404 for command {ctx.command}")
+ await ctx.send("There does not seem to be anything matching your query.")
ctx.bot.stats.incr("errors.api_error_404")
elif e.status == 400:
content = await e.response.json()
@@ -308,12 +299,12 @@ class ErrorHandler(Cog):
await ctx.send("According to the API, your request is malformed.")
ctx.bot.stats.incr("errors.api_error_400")
elif 500 <= e.status < 600:
- await ctx.send("Sorry, there seems to be an internal issue with the API.")
log.warning(f"API responded with {e.status} for command {ctx.command}")
+ await ctx.send("Sorry, there seems to be an internal issue with the API.")
ctx.bot.stats.incr("errors.api_internal_server_error")
else:
- await ctx.send(f"Got an unexpected status code from the API (`{e.status}`).")
log.warning(f"Unexpected API response for command {ctx.command}: {e.status}")
+ await ctx.send(f"Got an unexpected status code from the API (`{e.status}`).")
ctx.bot.stats.incr(f"errors.api_error_{e.status}")
@staticmethod