Skip to content

Commit e9a306b

Browse files
authored
fix(Runner): improper use of exception, created a new one (#258)
1 parent aeaefc9 commit e9a306b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

silverback/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def __init__(self, container: Any):
1515
super().__init__(f"Invalid container type: {container.__class__}")
1616

1717

18+
class InvalidContainerConfigurationError(Exception):
19+
pass
20+
21+
1822
class UnregisteredTask(Exception):
1923
def __init__(self, task_name: str):
2024
super().__init__(f"Could not find task '{task_name}'.")

silverback/main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
from pydantic import BaseModel
2121
from taskiq import AsyncTaskiqDecoratedTask, TaskiqEvents
2222

23-
from .exceptions import ContainerTypeMismatchError, InvalidContainerTypeError, NoSignerLoaded
23+
from .exceptions import (
24+
ContainerTypeMismatchError,
25+
InvalidContainerConfigurationError,
26+
InvalidContainerTypeError,
27+
NoSignerLoaded,
28+
)
2429
from .settings import Settings
2530
from .state import StateSnapshot
2631
from .types import ScalarType, SilverbackID, TaskType
@@ -402,6 +407,8 @@ def broker_task_decorator(
402407
:class:`~silverback.exceptions.ContainerTypeMismatchError`:
403408
If there is a mismatch between `task_type` and the `container`
404409
type it should handle.
410+
:class:`~silverback.exceptions.ContainerConfigurationError`:
411+
If there is an issue with the arguments provided.
405412
"""
406413
if (
407414
(task_type is TaskType.NEW_BLOCK and not isinstance(container, BlockContainer))
@@ -422,9 +429,10 @@ def broker_task_decorator(
422429

423430
elif isinstance(container, ContractEventWrapper):
424431
if len(container.events) != 1:
425-
raise InvalidContainerTypeError(
432+
raise InvalidContainerConfigurationError(
426433
f"Requires exactly 1 event to unwrap: {container.events}"
427434
)
435+
428436
container = container.events[0]
429437

430438
# Register user function as task handler with our broker
@@ -466,7 +474,7 @@ def add_taskiq_task(
466474
# NOTE: Will clean up extra Nones in `encode_topics_to_string`
467475

468476
if unmatched_args := "', '".join(filter_args):
469-
raise InvalidContainerTypeError(
477+
raise InvalidContainerConfigurationError(
470478
f"Args are not available for filtering: '{unmatched_args}'."
471479
)
472480

@@ -479,7 +487,7 @@ def add_taskiq_task(
479487
if not cron_schedule or not pycron.has_been(
480488
cron_schedule, datetime.now() - timedelta(days=366)
481489
):
482-
raise InvalidContainerTypeError(
490+
raise InvalidContainerConfigurationError(
483491
f"'{cron_schedule}' is not a valid cron schedule"
484492
)
485493

0 commit comments

Comments
 (0)