improve error logging
This commit is contained in:
parent
3de920f54b
commit
1573d0b046
1 changed files with 43 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
import io
|
||||
import logging
|
||||
import os
|
||||
import pprint
|
||||
import sys
|
||||
import textwrap
|
||||
import traceback
|
||||
|
@ -120,18 +121,57 @@ async def on_ready():
|
|||
log.info(bot.user.id)
|
||||
log.info("-------------")
|
||||
|
||||
bot.app_info = await bot.application_info()
|
||||
bot.owner = bot.app_info.owner
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_command_error(ctx, error):
|
||||
if isinstance(error, commands.CommandNotFound):
|
||||
return
|
||||
|
||||
if isinstance(error, commands.NoPrivateMessage):
|
||||
if isinstance(
|
||||
error,
|
||||
(
|
||||
commands.UserInputError,
|
||||
commands.CheckFailure,
|
||||
),
|
||||
):
|
||||
await ctx.send(error)
|
||||
return
|
||||
|
||||
log.exception(error)
|
||||
await ctx.send(error)
|
||||
log.error(error, exc_info=error)
|
||||
timestamp = int(ctx.message.created_at.timestamp())
|
||||
await ctx.bot.owner.send(
|
||||
f"# Command Error Occurred: {error}\n\n"
|
||||
f"```\n{"".join(traceback.format_exception(error))}```\n\n"
|
||||
f"## Context\n"
|
||||
f"**From:** {ctx.author.mention} ({ctx.author.name})\n"
|
||||
f"<t:{timestamp}>, <t:{timestamp}:R> | [Jump to Command]({ctx.message.jump_url}) | <#{ctx.channel.id}>\n"
|
||||
)
|
||||
await ctx.send(
|
||||
f"Error: {error}\n\n**Note:** Infinidoge (Developer) has already been sent a notification that an error occurred and will come investigate when available."
|
||||
)
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_error(event, *args, **kwargs):
|
||||
ptraceback = "".join(traceback.format_exc())
|
||||
pargs = pprint.pformat(args)
|
||||
pkwargs = pprint.pformat(kwargs)
|
||||
try:
|
||||
await bot.owner.send(
|
||||
f"# Error Occurred: Event `{event}`"
|
||||
f"```\n{ptraceback}```"
|
||||
f"## args"
|
||||
f"```\n{pargs}\n```"
|
||||
f"## kwargs"
|
||||
f"```\n{pkwargs}\n```"
|
||||
)
|
||||
except: # Don't want recursive errors
|
||||
pass
|
||||
|
||||
log.error(f"Error in event {event}.\nargs={pargs}\nkwargs={pkwargs}", exc_info=sys.exc_info())
|
||||
|
||||
|
||||
@bot.command(hidden=True)
|
||||
|
|
Loading…
Reference in a new issue