Source code for beaker.exceptions

"""
Exceptions that can be raised by the :class:`~beaker.Beaker` client.

.. tip::
    All exceptions inherit from :class:`BeakerError` other than :exc:`HTTPError`,
    which is re-exported from :exc:`requests.exceptions.HTTPError`,
    and :exc:`ValidationError`, which is re-exported from `pydantic <https://pydantic-docs.helpmanual.io/>`_.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Optional

from pydantic import ValidationError  # noqa: F401, re-imported here for convenience
from requests.exceptions import (  # noqa: F401, re-imported here for convenience
    HTTPError,
    RequestException,
)

if TYPE_CHECKING:
    from .data_model.experiment import Task
    from .data_model.job import Job

ValidationError.__doc__ = """
Raised when data passed into a :mod:`DataModel <beaker.data_model>` is invalid.
"""


__all__ = [
    "BeakerError",
    "ValidationError",
    "HTTPError",
    "RequestException",
    "BeakerPermissionsError",
    "NotFoundError",
    "AccountNotFound",
    "OrganizationNotFound",
    "OrganizationNotSet",
    "ConfigurationError",
    "ImageNotFound",
    "ImageConflict",
    "WorkspaceNotFound",
    "WorkspaceWriteError",
    "WorkspaceConflict",
    "ClusterNotFound",
    "ClusterConflict",
    "ExperimentNotFound",
    "ExperimentConflict",
    "DatasetConflict",
    "DatasetNotFound",
    "UnexpectedEOFError",
    "JobNotFound",
    "WorkspaceNotSet",
    "NodeNotFound",
    "DatasetWriteError",
    "DatasetReadError",
    "SecretNotFound",
    "GroupConflict",
    "GroupNotFound",
    "DuplicateJobError",
    "DuplicateExperimentError",
    "TaskNotFound",
    "ChecksumFailedError",
    "TaskStoppedError",
    "JobFailedError",
    "JobTimeoutError",
    "ExperimentSpecError",
    "ThreadCanceledError",
]


[docs]class BeakerError(Exception): """ Base class for all Beaker errors other than :exc:`HTTPError`, which is re-exported from :exc:`requests.exceptions.HTTPError`, and :exc:`ValidationError`, which is re-exported from `pydantic <https://pydantic-docs.helpmanual.io/>`_. """
[docs]class BeakerPermissionsError(BeakerError): """ Raised when a user doesn't have sufficient permissions to perform an action. """
[docs]class NotFoundError(BeakerError): """ Base class for all "not found" error types. """
[docs]class AccountNotFound(NotFoundError): pass
[docs]class OrganizationNotFound(NotFoundError): """ Raised when a specified organization doesn't exist. """
[docs]class OrganizationNotSet(BeakerError): """ Raised when an identifying doesn't start with an organization name and :data:`Config.default_org <beaker.Config.default_org>` is not set. """
[docs]class ConfigurationError(BeakerError): """ Raised when the :class:`~beaker.Config` fails to instantiate. """
[docs]class ImageNotFound(NotFoundError): pass
[docs]class ImageConflict(BeakerError): """ Raised when attempting to create/rename an image if an image by that name already exists. """
[docs]class WorkspaceNotFound(NotFoundError): pass
[docs]class WorkspaceWriteError(BeakerError): """ Raised when attempting to modify or add to a workspace that's been archived. """
[docs]class WorkspaceConflict(BeakerError): """ Raised when attempting to create/rename a workspace if a workspace by that name already exists. """
[docs]class ClusterNotFound(NotFoundError): pass
[docs]class ClusterConflict(BeakerError): """ Raised when attempting to create a cluster if a cluster by that name already exists. """
[docs]class ExperimentNotFound(NotFoundError): pass
[docs]class ExperimentConflict(BeakerError): """ Raised when attempting to create/rename/stop an experiment that already exists or is already stopped. """
[docs]class DatasetConflict(BeakerError): """ Raised when attempting to create/rename a dataset if a dataset by that name already exists. """
[docs]class DatasetNotFound(NotFoundError): pass
[docs]class UnexpectedEOFError(BeakerError): """ Raised when creating a dataset when an empty source file is encountered. """
[docs]class JobNotFound(NotFoundError): pass
[docs]class WorkspaceNotSet(BeakerError): """ Raised when workspace argument is not provided and there is no default workspace set. """
[docs]class NodeNotFound(NotFoundError): pass
[docs]class DatasetWriteError(BeakerError): """ Raised when a write operation on a dataset fails because the dataset has already been committed. """
[docs]class DatasetReadError(BeakerError): """ Raised when a read operation on a dataset fails because the dataset hasn't been committed yet, or the :data:`~beaker.data_model.Dataset.storage` hasn't been set for some other reason. """
[docs]class SecretNotFound(NotFoundError): pass
[docs]class GroupConflict(BeakerError): """ Raised when attempting to create/rename a group if a group by that name already exists. """
[docs]class GroupNotFound(NotFoundError): pass
[docs]class DuplicateJobError(BeakerError): """ Raised when duplicate jobs are passed into a method that expects unique jobs. """
[docs]class DuplicateExperimentError(BeakerError): """ Raised when duplicate experiments are passed into a method that expects unique experiments. """
[docs]class TaskNotFound(NotFoundError): pass
[docs]class ChecksumFailedError(BeakerError): """ Raised when a downloaded file from a Beaker dataset is corrupted. """
[docs]class TaskStoppedError(BeakerError): def __init__(self, msg: Optional[str] = None, task: Optional[Task] = None): super().__init__(msg) self.task = task
[docs]class JobFailedError(BeakerError): def __init__(self, msg: Optional[str] = None, job: Optional[Job] = None): super().__init__(msg) self.job = job
[docs]class JobTimeoutError(BeakerError, TimeoutError): pass
[docs]class ExperimentSpecError(BeakerError): pass
[docs]class ThreadCanceledError(BeakerError): pass