From c0582ed8f5fb5ce6813e5f071714e74bb3e23c14 Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Tue, 12 Sep 2023 21:12:58 +0200 Subject: [PATCH] Inform bot managers about errors if possible --- robocop_ng/__main__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/robocop_ng/__main__.py b/robocop_ng/__main__.py index de4c2be0..b0c1cd18 100755 --- a/robocop_ng/__main__.py +++ b/robocop_ng/__main__.py @@ -8,6 +8,8 @@ from discord.ext import commands from discord.ext.commands import CommandError, Context +from robocop_ng.helpers.notifications import report_critical_error + if len(sys.argv[1:]) != 1: sys.stderr.write("usage: ") sys.exit(1) @@ -140,6 +142,25 @@ async def on_command(ctx): async def on_error(event: str, *args, **kwargs): log.exception(f"Error on {event}:") + exception = sys.exception() + is_report_allowed = any( + [ + not isinstance(exception, x) + for x in [ + discord.RateLimited, + discord.GatewayNotFound, + discord.InteractionResponded, + discord.LoginFailure, + ] + ] + ) + if exception is not None and is_report_allowed: + await report_critical_error( + bot, + exception, + additional_info={"Event": event, "args": args, "kwargs": kwargs}, + ) + @bot.event async def on_command_error(ctx: Context, error: CommandError):