From 356922f4de3050426ab5501ce4f27108b1ad99be Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Wed, 19 May 2021 15:36:16 +0200 Subject: [PATCH] Improve global exception handler log messages * Merge pull request #4980 * Improve global exception handler log messages --- redbot/__main__.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/redbot/__main__.py b/redbot/__main__.py index 9cf8bdb98..8810ef544 100644 --- a/redbot/__main__.py +++ b/redbot/__main__.py @@ -446,13 +446,18 @@ def global_exception_handler(red, loop, context): """ Logs unhandled exceptions in other tasks """ - msg = context.get("exception", context["message"]) + exc = context.get("exception") # These will get handled later when it *also* kills loop.run_forever - if not isinstance(msg, (KeyboardInterrupt, SystemExit)): - if isinstance(msg, Exception): - log.critical("Caught unhandled exception in task:\n", exc_info=msg) - else: - log.critical("Caught unhandled exception in task: %s", msg) + if exc is not None and isinstance(exc, (KeyboardInterrupt, SystemExit)): + return + # Maybe in the future we should handle some of the other things + # that the default exception handler handles, but this should work fine for now. + log.critical( + "Caught unhandled exception in %s:\n%s", + context.get("future", "event loop"), + context["message"], + exc_info=exc, + ) def red_exception_handler(red, red_task: asyncio.Future):