aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slack/error.py11
-rw-r--r--slack/slack_user.py7
-rw-r--r--slack/task.py8
3 files changed, 21 insertions, 5 deletions
diff --git a/slack/error.py b/slack/error.py
index 1d9a975..ed42ca8 100644
--- a/slack/error.py
+++ b/slack/error.py
@@ -46,6 +46,15 @@ class SlackApiError(Exception):
self.response = response
+class SlackError(Exception):
+ def __init__(self, workspace: SlackWorkspace, error: str):
+ super().__init__(
+ f"{self.__class__.__name__}: workspace={workspace}, error={error}"
+ )
+ self.workspace = workspace
+ self.error = error
+
+
def format_exception(e: BaseException):
if isinstance(e, HttpError):
return (
@@ -57,5 +66,7 @@ def format_exception(e: BaseException):
f"Error from Slack API method {e.method} with params {e.params} for workspace "
f"{e.workspace.name}: {e.response}"
)
+ elif isinstance(e, SlackError):
+ return f"Error occurred in workspace {e.workspace.name}: {e.error}"
else:
return f"Unknown error occurred: {e.__class__.__name__}: {e}"
diff --git a/slack/slack_user.py b/slack/slack_user.py
index 8b9888d..2356eaf 100644
--- a/slack/slack_user.py
+++ b/slack/slack_user.py
@@ -4,6 +4,7 @@ from typing import TYPE_CHECKING
import weechat
+from slack.error import SlackError
from slack.shared import shared
from slack.util import with_color
@@ -98,9 +99,9 @@ class SlackUsergroup:
@classmethod
async def create(cls, workspace: SlackWorkspace, id: str):
info_response = await workspace.api.fetch_usergroups_info([id])
- # TODO: Handle failed ids
- usergroup_info = info_response["results"][0]
- return cls(workspace, usergroup_info)
+ if not info_response["results"] or info_response["results"][0]["id"] != id:
+ raise SlackError(workspace, f"Couldn't find user group {id}")
+ return cls(workspace, info_response["results"][0])
def handle(self) -> str:
return self._info["handle"]
diff --git a/slack/task.py b/slack/task.py
index 2f68181..763f605 100644
--- a/slack/task.py
+++ b/slack/task.py
@@ -20,7 +20,7 @@ from uuid import uuid4
import weechat
-from slack.error import HttpError, SlackApiError, format_exception
+from slack.error import HttpError, SlackApiError, SlackError, format_exception
from slack.log import print_error
from slack.shared import shared
from slack.util import get_callback_name
@@ -120,7 +120,11 @@ def task_runner(task: Task[Any], response: Any):
or not weechat_task_cb_in_stack
and create_task_in_stack == 1
):
- if isinstance(e, HttpError) or isinstance(e, SlackApiError):
+ if (
+ isinstance(e, HttpError)
+ or isinstance(e, SlackApiError)
+ or isinstance(e, SlackError)
+ ):
exception_str = format_exception(e)
print_error(f"{exception_str}, task: {task}")
else: