"""Custom exceptions."""
from pydantic import ValidationError
[docs]
def log_pydantic(e: ValidationError) -> str:
"""Log a pydantic validation error correctly."""
errors = e.errors()
return '. '.join([f'{err["loc"][0]}: {err["msg"]}' for err in errors])
[docs]
class OtterError(Exception):
"""Base class for all application-specific exceptions."""
# Step-related errors
[docs]
class StepInvalidError(OtterError):
"""Raise when a step is invalid somehow."""
[docs]
class StepFailedError(OtterError):
"""Raise when a step fails somehow."""
# Task-related errors
[docs]
class TaskAbortedError(OtterError):
"""Raise when a task is aborted."""
def __init__(self) -> None:
super().__init__('another task failed, task aborted')
[docs]
class TaskValidationError(OtterError):
"""Raise when a task fails validation."""
# Other errors
[docs]
class DownloadError(OtterError):
"""Raise when an error occurs during a download."""
[docs]
class NotFoundError(OtterError):
"""Raise when something is not found."""
def __init__(self, msg: str | None = None) -> None:
super().__init__(msg)
[docs]
class PreconditionFailedError(OtterError):
"""Raise when a precondition fails."""
[docs]
class ScratchpadError(OtterError):
"""Raise when a key is not found in the scratchpad."""
[docs]
class StorageError(OtterError):
"""Raise when an error occurs in a storage class."""