# Error Handling

Jigu provides several custom exceptions that allow you to handle errors and recover from exceptional cases that could potentially come up during normal execution flow.


class JiguException(Exception):
    pass


class JiguWarning(Warning):
    pass


### Validation Errors


class ValidationError(JiguException):
    """Ambiguous validation check failed."""


class DenomIncompatibleError(ValidationError, ValueError):
    """An operation requiring compatible Coins encountered incompatible denoms."""


class InvalidAccAddress(ValidationError, ValueError):
    """An incorrect value was passed into a method that expects a valid Account
    address (Bech32-encoded address prefixed with terra-)."""


class InvalidValAddress(ValidationError, ValueError):
    """An incorrect value was passed into a method that expects a valid Validator
    (operator) address (Bech32-encoded address prefixed with terravaloper-)."""


class InvalidValConsAddress(ValidationError, ValueError):
    """An incorrect value was passed into a method that expects a valid Validator
    (consensus) address (Bech32-encoded pubkey prefixed with terravalcons-)."""


class InvalidAccPubKey(ValidationError, ValueError):
    """An incorrect value was passed into a method that expects a valid Account
    public key (Bech32-encoded pubkey prefixed with terrapub-)."""


class InvalidValPubKey(ValidationError, ValueError):
    """An incorrect value was passed into a method that expects a valid Validator
    public key (Bech32-encoded pubkey prefixed with terravalpub-)."""


class InvalidValConsPubKey(ValidationError, ValueError):
    """An incorrect value was passed into a method that expects a valid Validator
    Consensus (Tendermint) pubkey (Bech32-encoded pubkey prefixed with terravalconspub-)."""


class InvalidParamChange(ValidationError, ValueError):
    """The parameter change does not adhere to specified schema."""


class JsonSchemaValidationError(ValidationError, JsonSchemaException):
    """Failed attempt to deserialize an object using a :class:`JsonDeserializable`."""

### Terra Node IO Errors


class JiguRequestError(JiguException):
    def __init__(
        self, status_code: int, error_msg: str, request: requests.Request = None
    ):
        Exception.__init__(self, f"({status_code}) {error_msg}")
        self.status_code = status_code
        self.message = error_msg
        self.request = request


class UnhandledResponse(JiguRequestError):
    """Jigu did not handle the response, but status code 200."""


class BadRequest(JiguRequestError):
    """Malformed request on the part of the user. (4xx errors)"""


class LcdInternalError(JiguRequestError):
    """An error occured on the server while processing the request. (5xx errors)"""


### RPC Errors


class RpcError(JiguRequestError):
    """Error at the RPC node level. Status code is RPC status code, not HTTP."""


class RpcInternalError(RpcError):
    """An internal error occured in the RPC node."""


### Codespace Errors
class CodespaceError(JiguException):
    """A more specific node error with information about the originating module."""

    def __init__(self, codespace: str, code: int, message: str, **kwargs):
        Exception.__init__(self, f"{codespace} (code {code}) {message}")
        self.codespace = codespace
        self.code = code
        self.message = message
        for k, v in kwargs.items():
            self.__setattr__(k, v)


#### TX Errors


class TxError(JiguException):
    """Broadcasting error due to something wrong with the transaction's content."""

    def __init__(self, message: str, tx, broadcast_result=None):
        Exception.__init__(self, message)
        self.message = message
        self.tx = tx
        self.broadcast_result = broadcast_result


class TxCodespaceError(CodespaceError, TxError):
    """Broadcasting error due to something wrong in the transaction's message content.
    (more specific and due to an error in the message, like denom not existing)."""


class InsufficientFee(TxCodespaceError, ValueError):
    """Transaction was not processed due to insufficient fees."""


class OutOfGasException(TxCodespaceError):
    """Transaction was accepted but validator ran out of gas while processing."""

### Misc Errors


class DenomNotFound(JiguException, KeyError):
    """The requested denomination as not found."""


Updated on: 2/11/2020, 10:12:45 PM