aboutsummaryrefslogtreecommitdiffstats
path: root/slack
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-10-15 02:30:05 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:54 +0100
commit3785cec18f56afb0c9b098ff700492543fe63859 (patch)
tree7723f7dd77e28052690a2fe25079977b92ce902d /slack
parent4143e3c8e907a67a4105ef7450a6523c20f4f0fe (diff)
downloadwee-slack-3785cec18f56afb0c9b098ff700492543fe63859.tar.gz
Catch errors when rendering message
Diffstat (limited to 'slack')
-rw-r--r--slack/slack_message.py47
1 files 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"<Error rendering message {self.ts}, error id: {uncaught_error.id}>"
+ 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"<Error rendering message, error id: {uncaught_error.id}>"
+ text = f"<Error rendering message {self.ts}, error id: {uncaught_error.id}>"
block_lines.append(
[with_color(shared.config.color.render_error.value, text)]
)