From 137adbabf8845b4a49072e656480cd258d464c9c Mon Sep 17 00:00:00 2001 From: Tim Savage Date: Fri, 22 Oct 2021 12:25:43 +1100 Subject: [PATCH] Put an exception handler around console.print This is to handle any failures in the print method and defer exception handling to the Handler.handleErrors method. --- rich/logging.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rich/logging.py b/rich/logging.py index c193ee5a..47ca7d42 100644 --- a/rich/logging.py +++ b/rich/logging.py @@ -150,7 +150,10 @@ class RichHandler(Handler): log_renderable = self.render( record=record, traceback=traceback, message_renderable=message_renderable ) - self.console.print(log_renderable) + try: + self.console.print(log_renderable) + except Exception: + self.handleError(record) def render_message(self, record: LogRecord, message: str) -> "ConsoleRenderable": """Render message text in to Text.