from __future__ import (
annotations,
)
from typing import (
TYPE_CHECKING,
)
from minos.common import (
MinosException,
)
if TYPE_CHECKING:
from .models import (
Aggregate,
AggregateDiff,
)
[docs]class AggregateException(MinosException):
"""Base Aggregate module exception"""
[docs]class EventRepositoryException(AggregateException):
"""Base event repository exception."""
[docs]class EventRepositoryConflictException(EventRepositoryException):
"""Exception to be raised when some ``EventEntry`` raises a conflict."""
[docs] def __init__(self, error_message: str, offset: int):
super().__init__(error_message)
self.offset = offset
[docs]class TransactionRepositoryException(AggregateException):
"""Base transaction repository exception."""
[docs]class TransactionRepositoryConflictException(TransactionRepositoryException):
"""Exception to be raised when a transactions has invalid status."""
[docs]class TransactionNotFoundException(TransactionRepositoryException):
"""Exception to be raised when some transaction is not found on the repository."""
[docs]class SnapshotRepositoryException(AggregateException):
"""Base snapshot exception."""
[docs]class SnapshotRepositoryConflictException(SnapshotRepositoryException):
"""Exception to be raised when current version is newer than the one to be processed."""
[docs] def __init__(self, previous: Aggregate, aggregate_diff: AggregateDiff):
self.previous = previous
self.aggregate_diff = aggregate_diff
super().__init__(
f"Version for {repr(previous.classname)} aggregate must be "
f"greater than {previous.version}. Obtained: {aggregate_diff.version}"
)
[docs]class AggregateNotFoundException(SnapshotRepositoryException):
"""Exception to be raised when some aggregate is not found on the repository."""
[docs]class DeletedAggregateException(SnapshotRepositoryException):
"""Exception to be raised when some aggregate is already deleted from the repository."""
[docs]class ValueObjectException(AggregateException):
"""If an attribute of an immutable class is modified, this exception will be raised"""