Source code for koi_net.exceptions

"""KOI-net library exceptions.

Exception hierarchy (conceptually)::

  KoiNetError
    BuildError
    RequestError
      ClientError
        SelfRequestError
        PartialNodeQueryError
        NodeNotFoundError
      TransportError
      ServerError
        RemoteProtocolError
          RemoteUnknownNodeError
          RemoteInvalidKeyError
          RemoteInvalidSignatureError
          RemoteInvalidTargetError
    ProtocolError
      UnknownNodeError
      InvalidKeyError
      InvalidSignatureError
      InvalidTargetError
    MissingEnvVarsError
"""


# BASE EXCEPTION
[docs] class KoiNetError(Exception): """Base exception.""" pass
# BUILD ERRORS
[docs] class BuildError(KoiNetError): """Raised when errors occur in build process.""" pass
# NETWORK REQUEST ERRORS
[docs] class RequestError(KoiNetError): """Base for network request errors.""" pass
# CLIENT ERRORS
[docs] class ClientError(RequestError): """Raised when this node makes an invalid request.""" pass
[docs] class SelfRequestError(ClientError): """Raised when this node tries to request itself.""" pass
[docs] class PartialNodeQueryError(ClientError): """Raised when this node attempts to query a partial node.""" pass
[docs] class NodeNotFoundError(ClientError): """Raised when this node cannot find a node's URL.""" pass
[docs] class TransportError(RequestError): """Raised when a transport error occurs during a request.""" pass
# SERVER ERRORS
[docs] class ServerError(RequestError): """Raised when an server error occurs during a request.""" pass
# PROTOCOL ERRORS
[docs] class RemoteProtocolError(ServerError): """Base for protocol errors raised by peer node.""" pass
[docs] class RemoteUnknownNodeError(RemoteProtocolError): """Raised by peer node when this node is unknown.""" pass
[docs] class RemoteInvalidKeyError(RemoteProtocolError): """Raised by peer node when this node's public key doesn't match their RID.""" pass
[docs] class RemoteInvalidSignatureError(RemoteProtocolError): """Raised by peer node when this node's envelope signature is invalid.""" pass
[docs] class RemoteInvalidTargetError(RemoteProtocolError): """Raised by peer node when this node's envelope target is not it's RID.""" pass
[docs] class ProtocolError(KoiNetError): """Base for protocol errors raised by this node.""" pass
[docs] class UnknownNodeError(ProtocolError): """Raised when peer node is unknown.""" pass
[docs] class InvalidKeyError(ProtocolError): """Raised when peer node's public key doesn't match their RID.""" pass
[docs] class InvalidSignatureError(ProtocolError): """Raised when peer node's envelope signature is invalid.""" pass
[docs] class InvalidTargetError(ProtocolError): """Raised when peer node's target is not this node.""" pass
[docs] class MissingEnvVarsError(KoiNetError): """Raised when required environment variables are missing.""" def __init__(self, message: str, vars: list[str]): super().__init__(message) self.vars = vars