Skip to content

Commit 00d7089

Browse files
committed
Added new base class for exceptions, added templates
Signed-off-by: chandr-andr (Kiselev Aleksandr) <[email protected]>
1 parent f4c03bc commit 00d7089

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

taskiq/exceptions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
from typing import Optional
2+
13
from izulu import root
24

35

46
class TaskiqError(root.Error):
57
"""Base exception for all errors."""
68

79
__template__ = "Exception occurred: {description}"
8-
description: str
10+
description: Optional[str] = None
911

1012

1113
class TaskiqResultTimeoutError(TaskiqError):
1214
"""Waiting for task results has timed out."""
1315

1416
__template__ = "Waiting for task results has timed out, timeout={timeout}"
15-
timeout: float
17+
timeout: Optional[float] = None
1618

1719

1820
class BrokerError(TaskiqError):
@@ -54,7 +56,8 @@ class ResultIsReadyError(ResultBackendError):
5456
class SecurityError(TaskiqError):
5557
"""Security related exception."""
5658

57-
__template__ = "Base exception for all security errors"
59+
__template__ = "Security exception occurred: {description}"
60+
description: str
5861

5962

6063
class NoResultError(TaskiqError):

taskiq/serialization.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,10 @@ def exception_to_python(
378378
if not isinstance(cls, type) or not issubclass(cls, BaseException):
379379
fake_exc_type = exc_type if exc_module is None else f"{exc_module}.{exc_type}"
380380
raise taskiq.exceptions.SecurityError(
381-
f"Expected an exception class, got {fake_exc_type} with payload {exc_msg}",
381+
description=(
382+
f"Expected an exception class, "
383+
f"got {fake_exc_type} with payload {exc_msg}"
384+
),
382385
)
383386

384387
# XXX: Without verifying `cls` is actually an exception class,

0 commit comments

Comments
 (0)