From 3785cec18f56afb0c9b098ff700492543fe63859 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sun, 15 Oct 2023 02:30:05 +0200 Subject: Catch errors when rendering message --- slack/slack_message.py | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/slack/slack_message.py b/slack/slack_message.py index 2da4042..39d6e57 100644 --- a/slack/slack_message.py +++ b/slack/slack_message.py @@ -637,26 +637,33 @@ class SlackMessage: if self._rendered_message is not None and not rerender: return self._rendered_message - me_prefix = ( - f"{await self.nick()} " - if self._message_json.get("subtype") == "me_message" - else "" - ) + try: + me_prefix = ( + f"{await self.nick()} " + if self._message_json.get("subtype") == "me_message" + else "" + ) + + parsed_message = self._parse_message_text(rerender) + text = "".join( + [ + text if isinstance(text, str) else await text.resolve() + for text in parsed_message + ] + ) + text_edited = ( + f" {with_color(shared.config.color.edited_message_suffix.value, '(edited)')}" + if self._message_json.get("edited") + else "" + ) + reactions = await self._create_reactions_string() + self._rendered_message = me_prefix + text + text_edited + reactions + except Exception as e: + uncaught_error = UncaughtError(e) + print_error(store_and_format_uncaught_error(uncaught_error)) + text = f"" + self._rendered_message = with_color(shared.config.color.render_error.value, text) - parsed_message = self._parse_message_text(rerender) - text = "".join( - [ - text if isinstance(text, str) else await text.resolve() - for text in parsed_message - ] - ) - text_edited = ( - f" {with_color(shared.config.color.edited_message_suffix.value, '(edited)')}" - if self._message_json.get("edited") - else "" - ) - reactions = await self._create_reactions_string() - self._rendered_message = me_prefix + text + text_edited + reactions return self._rendered_message async def render_message( @@ -900,7 +907,7 @@ class SlackMessage: except Exception as e: uncaught_error = UncaughtError(e) print_error(store_and_format_uncaught_error(uncaught_error)) - text = f"" + text = f"" block_lines.append( [with_color(shared.config.color.render_error.value, text)] ) -- cgit