Skip to content

Repository Errors

repository_errors

RepositoryPort error classes for the infrastructure layer.

Provides structured error types for repository operations such as
save failures, deletion of non-existent aggregates, and retrieval errors.

RepositoryError

Bases: Error[dict[str, object]]

Generic error raised when a repository operation fails.

This is the base error for all repository-level failures. Concrete
implementations may raise this or more specific subclasses.

Source code in src/forging_blocks/infrastructure/errors/repository_errors.py
class RepositoryError(Error[dict[str, object]]):
    """Generic error raised when a repository operation fails.

    This is the base error for all repository-level failures. Concrete
    implementations may raise this or more specific subclasses.
    """

RepositoryNotFoundError

Bases: RepositoryError

Error raised when attempting to delete or retrieve an aggregate that does not exist.

Source code in src/forging_blocks/infrastructure/errors/repository_errors.py
class RepositoryNotFoundError(RepositoryError):
    """Error raised when attempting to delete or retrieve an aggregate that does not exist."""

    @classmethod
    def for_id(cls, entity_id: object) -> RepositoryNotFoundError:
        """Create an error for a specific missing aggregate ID.

        Args:
            entity_id: The identifier that was not found.

        Returns:
            A RepositoryNotFoundError with a descriptive message.
        """
        return cls(ErrorMessage(f"Aggregate with id '{entity_id}' not found."))

for_id(entity_id: object) -> RepositoryNotFoundError classmethod

Create an error for a specific missing aggregate ID.

Parameters:

Name Type Description Default
entity_id object

The identifier that was not found.

required

Returns:

Type Description
RepositoryNotFoundError

A RepositoryNotFoundError with a descriptive message.

Source code in src/forging_blocks/infrastructure/errors/repository_errors.py
@classmethod
def for_id(cls, entity_id: object) -> RepositoryNotFoundError:
    """Create an error for a specific missing aggregate ID.

    Args:
        entity_id: The identifier that was not found.

    Returns:
        A RepositoryNotFoundError with a descriptive message.
    """
    return cls(ErrorMessage(f"Aggregate with id '{entity_id}' not found."))