Source code for rics.translation.fetching.exceptions

"""Errors and warnings related to fethcing."""
from typing import Any, Iterable


[docs]class FetcherWarning(RuntimeWarning): """Base class for ``Fetcher`` warnings."""
[docs]class FetcherError(RuntimeError): """Base class for ``Fetcher`` exceptions."""
[docs]class ForbiddenOperationError(FetcherError): """Exception indicating that the ``Fetcher`` does not support an operation.""" def __init__(self, operation: str, reason: str = "not supported by this fetcher.") -> None: super().__init__(f"Operation '{operation}' " + reason) self.operation = operation
[docs]class ImplementationError(FetcherError): """An underlying implementation did something wrong."""
[docs]class UnknownPlaceholderError(FetcherError): """Caller requested unknown placeholder name(s)."""
[docs]class UnknownIdError(FetcherError): """Caller requested unknown id(s)."""
[docs]class UnknownSourceError(FetcherError): """Caller requested unknown source(s).""" def __init__(self, unknown_sources: Iterable[Any], sources: Iterable[Any]) -> None: super().__init__(f"Sources {set(unknown_sources)} not recognized: Known {sources=}.")
[docs]class DuplicateSourceWarning(FetcherWarning): """Duplicate sources detected."""
[docs]class DuplicateSourceError(FetcherError): """Multiple translations for the same source received."""