aboutsummaryrefslogtreecommitdiffstats
path: root/slack/error.py
diff options
context:
space:
mode:
Diffstat (limited to 'slack/error.py')
-rw-r--r--slack/error.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/slack/error.py b/slack/error.py
index a92626d..8817759 100644
--- a/slack/error.py
+++ b/slack/error.py
@@ -1,6 +1,11 @@
from __future__ import annotations
+from dataclasses import dataclass, field
+from datetime import datetime
from typing import TYPE_CHECKING, Dict, Mapping, Sequence, Union
+from uuid import uuid4
+
+from slack.shared import shared
if TYPE_CHECKING:
from slack_api.slack_common import SlackErrorResponse
@@ -55,18 +60,32 @@ class SlackError(Exception):
self.error = error
-def format_exception(e: BaseException):
+@dataclass
+class UncaughtError:
+ id: str = field(init=False)
+ exception: BaseException
+
+ def __post_init__(self):
+ self.id = str(uuid4())
+ self.time = datetime.now()
+
+
+def store_and_format_exception(e: BaseException):
+ uncaught_error = UncaughtError(e)
+ shared.uncaught_errors.append(uncaught_error)
+ stack_msg = f"(run /slack debug error {uncaught_error.id} for stack trace)"
+
if isinstance(e, HttpError):
return (
f"Error calling URL {e.url}: return code: {e.return_code}, "
- f"http status code: {e.http_status_code}, error: {e.error}"
+ f"http status code: {e.http_status_code}, error: {e.error} {stack_msg}"
)
elif isinstance(e, SlackApiError):
return (
f"Error from Slack API method {e.method} with params {e.params} for workspace "
- f"{e.workspace.name}: {e.response}"
+ f"{e.workspace.name}: {e.response} {stack_msg}"
)
elif isinstance(e, SlackError):
- return f"Error occurred in workspace {e.workspace.name}: {e.error}"
+ return f"Error occurred in workspace {e.workspace.name}: {e.error} {stack_msg}"
else:
- return f"Unknown error occurred: {e.__class__.__name__}: {e}"
+ return f"Unknown error occurred: {e.__class__.__name__}: {e} {stack_msg}"