aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-01-29 00:19:25 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:53 +0100
commit95f05c435a4db808ab490e42b063aa54f3cb2a2e (patch)
tree02d0e742ead22a83da9c65bb31bfadc6c86271a3
parent8f3a5bdc1ec969ae069451ddf8c68ade002782bc (diff)
downloadwee-slack-95f05c435a4db808ab490e42b063aa54f3cb2a2e.tar.gz
Print error when fetching users/usergroups fail
-rw-r--r--slack/log.py10
-rw-r--r--slack/slack_message.py3
2 files changed, 13 insertions, 0 deletions
diff --git a/slack/log.py b/slack/log.py
index e33b744..b132c0e 100644
--- a/slack/log.py
+++ b/slack/log.py
@@ -1,11 +1,15 @@
from __future__ import annotations
from enum import IntEnum
+from typing import Set
import weechat
+from slack.error import format_exception
from slack.shared import shared
+printed_exceptions: Set[BaseException] = set()
+
class LogLevel(IntEnum):
TRACE = 1
@@ -21,6 +25,12 @@ def print_error(message: str):
weechat.prnt("", f"{weechat.prefix('error')}{shared.SCRIPT_NAME}: {message}")
+def print_exception_once(e: BaseException):
+ if e not in printed_exceptions:
+ print_error(format_exception(e))
+ printed_exceptions.add(e)
+
+
def log(level: LogLevel, message: str):
if level >= LogLevel.INFO:
prefix = weechat.prefix("error") if level >= LogLevel.ERROR else "\t"
diff --git a/slack/slack_message.py b/slack/slack_message.py
index dbae819..cfae6cc 100644
--- a/slack/slack_message.py
+++ b/slack/slack_message.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import re
from typing import TYPE_CHECKING, List, Match, Optional
+from slack.log import print_exception_once
from slack.shared import shared
from slack.slack_user import SlackUser, SlackUsergroup, format_bot_nick
from slack.task import gather
@@ -91,6 +92,7 @@ class SlackMessage:
shared.config.color.user_mention_color.value, "@" + user.nick()
)
else:
+ print_exception_once(user)
return f"@{user_id}"
def unfurl_usergroup(usergroup_id: str):
@@ -101,6 +103,7 @@ class SlackMessage:
"@" + usergroup.handle(),
)
else:
+ print_exception_once(usergroup)
return f"@{usergroup_id}"
return re_mention.sub(unfurl_ref, message)