aboutsummaryrefslogtreecommitdiffstats
path: root/slack/log.py
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 /slack/log.py
parent8f3a5bdc1ec969ae069451ddf8c68ade002782bc (diff)
downloadwee-slack-95f05c435a4db808ab490e42b063aa54f3cb2a2e.tar.gz
Print error when fetching users/usergroups fail
Diffstat (limited to 'slack/log.py')
-rw-r--r--slack/log.py10
1 files changed, 10 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"