From 95f05c435a4db808ab490e42b063aa54f3cb2a2e Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sun, 29 Jan 2023 00:19:25 +0100 Subject: Print error when fetching users/usergroups fail --- slack/log.py | 10 ++++++++++ slack/slack_message.py | 3 +++ 2 files changed, 13 insertions(+) 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) -- cgit