Source code for pydent.exceptions
"""
Exceptions (:mod:`pydent.exceptions`)
=====================================
.. currentmodule:: pydent.exceptions
Trident exceptions
"""
from typing import Type
from warnings import warn
[docs]class TridentBaseException(Exception):
"""Base exception for all trident errors."""
[docs]class TridentRequestError(TridentBaseException):
"""There was an ambiguous exception that occurred handling your request."""
def __init__(self, msg, response):
super().__init__(msg)
self.response = response
[docs]class AquariumError(TridentBaseException):
"""Aquarium raised an error."""
[docs]class AquariumModelNotFound(TridentBaseException):
"""Returned when Aquarium could not find a given model."""
[docs]class ForbiddenRequestError(TridentBaseException):
"""Raised when Trident attempts to make a request after requests have been
explicitly turned off."""
[docs]class TridentJSONDataIncomplete(TridentBaseException):
"""JSON data contains a null value and may be incomplete."""
[docs]class TridentLoginError(TridentBaseException):
"""Trident is not properly connected to the server.
Verify login credentials are correct.
"""
[docs]class TridentTimeoutError(TridentBaseException):
"""Trident took too long to respond."""
[docs]class TridentModelNotFoundError(TridentBaseException):
"""Trident could not find model in list of models."""
[docs]class AquariumModelError(TridentBaseException):
"""An error occurred with this Aquarium model."""
[docs]class NoSessionError(TridentBaseException):
"""There was no session attached to the model, but one is required."""
[docs]class SessionAlreadySet(TridentBaseException):
"""Cannot set session to models with a session already set."""
[docs]class PlannerException(TridentBaseException):
"""Generic planner Exception."""
[docs]class PlannerVerificationException(TridentBaseException):
"""Raised when object is not in plan but is required."""
[docs]class TridentDepreciationWarning(DeprecationWarning):
"""Raised when a feature or api is depreciated."""
[docs]class AquariumQueryLanguageValidationError(TridentBaseException):
"""Raised when aql is provided with an invalide query."""
# class WarningLimit(object):
#
# _limits = {}
#
# def __init__(self, msg: str, limit: int = 1, warning_class: Type = TridentDepreciationWarning):
# self.msg = msg
# self.warning_class = warning_class
# self._limits[msg] = (0, limit)
#
# def warn(self):
# a, b = self._limits[self.msg]
# if a < b:
# warn(self.warning_class(self.msg))
# self._limits[self.msg] = (a + 1, b)
# else:
# return
#
# def warn_with_limits(msg: str, limit: int):
# WarningLimit(msg, limit).warn()