Skip to content

Commit 88c2b9b

Browse files
committed
Added new exceptions to follow izulu flow
Signed-off-by: chandr-andr (Kiselev Aleksandr) <[email protected]>
1 parent b9dfa02 commit 88c2b9b

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

taskiq/brokers/inmemory_broker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from taskiq.abc.result_backend import AsyncResultBackend, TaskiqResult
88
from taskiq.depends.progress_tracker import TaskProgress
99
from taskiq.events import TaskiqEvents
10-
from taskiq.exceptions import TaskiqError
10+
from taskiq.exceptions import UnknownTaskError
1111
from taskiq.message import BrokerMessage
1212
from taskiq.receiver import Receiver
1313
from taskiq.utils import maybe_awaitable
@@ -156,7 +156,7 @@ async def kick(self, message: BrokerMessage) -> None:
156156
"""
157157
target_task = self.find_task(message.task_name)
158158
if target_task is None:
159-
raise TaskiqError(description="Unknown task.")
159+
raise UnknownTaskError(task_name=message.task_name)
160160

161161
receiver_cb = self.receiver.callback(message=message.message)
162162
if self.await_inplace:

taskiq/brokers/shared_broker.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from taskiq.abc.broker import AsyncBroker
66
from taskiq.decor import AsyncTaskiqDecoratedTask
7-
from taskiq.exceptions import TaskiqError
7+
from taskiq.exceptions import SharedBrokerListenError, SharedBrokerSendTaskError
88
from taskiq.kicker import AsyncKicker
99
from taskiq.message import BrokerMessage
1010

@@ -56,12 +56,7 @@ async def kick(self, message: BrokerMessage) -> None:
5656
:param message: message to send.
5757
:raises TaskiqError: if called.
5858
"""
59-
raise TaskiqError(
60-
description=(
61-
"You cannot use kiq directly on shared task "
62-
"without setting the default_broker."
63-
),
64-
)
59+
raise SharedBrokerSendTaskError
6560

6661
async def listen(self) -> AsyncGenerator[bytes, None]: # type: ignore
6762
"""
@@ -71,7 +66,7 @@ async def listen(self) -> AsyncGenerator[bytes, None]: # type: ignore
7166
7267
:raises TaskiqError: if called.
7368
"""
74-
raise TaskiqError(description="Shared broker cannot listen")
69+
raise SharedBrokerListenError
7570

7671
def _register_task(
7772
self,

taskiq/exceptions.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,38 @@ class BrokerError(TaskiqError):
2323
__template__ = "Base exception for all broker errors"
2424

2525

26+
class ListenError(TaskiqError):
27+
"""Error if the broker is unable to listen to the queue."""
28+
29+
30+
class SharedBrokerListenError(ListenError):
31+
"""Error when someone tries to listen to the queue with shared broker."""
32+
33+
__template__ = "Shared broker cannot listen"
34+
35+
2636
class SendTaskError(BrokerError):
2737
"""Error if the broker was unable to send the task to the queue."""
2838

2939
__template__ = "Cannot send task to the queue"
3040

3141

42+
class SharedBrokerSendTaskError(SendTaskError):
43+
"""Error when someone tries to send task with shared broker."""
44+
45+
__template__ = (
46+
"You cannot use kiq directly on shared task "
47+
"without setting the default_broker."
48+
)
49+
50+
51+
class UnknownTaskError(SendTaskError):
52+
"""Error if task is unknown."""
53+
54+
__template__ = "Cannot send unknown task to the queue, task name - {task_name}"
55+
task_name: str
56+
57+
3258
class ResultBackendError(TaskiqError):
3359
"""Base class for all ResultBackend errors."""
3460

0 commit comments

Comments
 (0)