From c7810823e89af0275bb6a091b3961cca00347324 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Thu, 16 Jan 2025 18:35:07 +0100 Subject: [PATCH] Core: Fix crash when trying to log an exception (#4313) * Fix crash when trying to log an exception In https://github.com/ArchipelagoMW/Archipelago/pull/3028, we added a new logging filter which checked `record.msg`. However, you can pass whatever you want into a logging call. In this case, what we missed was https://github.com/ArchipelagoMW/Archipelago/blob/ecc3094c70b3ee1f3e18d9299c03198564ec261a/MultiServer.py#L530C1-L530C37, where we pass an Exception object as the message. This currently causes a crash with the new filter. The logging module supports this. It has no typing and can handle passing objects as messages just fine. What you're supposed to use, as far as I understand it, is `record.getMessage()` instead of `record.msg`. * Update Utils.py Co-authored-by: Doug Hoskisson --------- Co-authored-by: Doug Hoskisson --- Utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Utils.py b/Utils.py index 8f5ba1a0..0aa81af1 100644 --- a/Utils.py +++ b/Utils.py @@ -521,8 +521,8 @@ def init_logging(name: str, loglevel: typing.Union[str, int] = logging.INFO, def filter(self, record: logging.LogRecord) -> bool: return self.condition(record) - file_handler.addFilter(Filter("NoStream", lambda record: not getattr(record, "NoFile", False))) - file_handler.addFilter(Filter("NoCarriageReturn", lambda record: '\r' not in record.msg)) + file_handler.addFilter(Filter("NoStream", lambda record: not getattr(record, "NoFile", False))) + file_handler.addFilter(Filter("NoCarriageReturn", lambda record: '\r' not in record.getMessage())) root_logger.addHandler(file_handler) if sys.stdout: formatter = logging.Formatter(fmt='[%(asctime)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')