Source code for bittensor.core.errors
from typing import Optional, TYPE_CHECKING
from async_substrate_interface.errors import (
SubstrateRequestException,
StorageFunctionNotFound,
BlockNotFound,
ExtrinsicNotFound,
)
if TYPE_CHECKING:
from bittensor.core.synapse import Synapse
# redundant aliases
SubstrateRequestException = SubstrateRequestException
StorageFunctionNotFound = StorageFunctionNotFound
BlockNotFound = BlockNotFound
ExtrinsicNotFound = ExtrinsicNotFound
class _ChainErrorMeta(type):
_exceptions: dict[str, Exception] = {}
def __new__(mcs, name, bases, attrs):
cls = super().__new__(mcs, name, bases, attrs)
mcs._exceptions.setdefault(cls.__name__, cls)
return cls
@classmethod
def get_exception_class(mcs, exception_name):
return mcs._exceptions[exception_name]
[docs]
class MaxSuccessException(Exception):
"""Raised when the POW Solver has reached the max number of successful solutions."""
[docs]
class MaxAttemptsException(Exception):
"""Raised when the POW Solver has reached the max number of attempts."""
[docs]
class ChainError(SubstrateRequestException, metaclass=_ChainErrorMeta):
"""Base error for any chain related errors."""
[docs]
@classmethod
def from_error(cls, error):
try:
error_cls = _ChainErrorMeta.get_exception_class(
error["name"],
)
except KeyError:
return cls(error)
else:
return error_cls(" ".join(error["docs"]))
[docs]
class ChainConnectionError(ChainError):
"""Error for any chain connection related errors."""
[docs]
class ChainTransactionError(ChainError):
"""Error for any chain transaction related errors."""
[docs]
class DelegateTakeTooHigh(ChainTransactionError):
"""
Delegate take is too high.
"""
[docs]
class DuplicateChild(ChainTransactionError):
"""
Duplicate child when setting children.
"""
[docs]
class HotKeyAccountNotExists(ChainTransactionError):
"""
The hotkey does not exist.
"""
[docs]
class IdentityError(ChainTransactionError):
"""
Error raised when an identity transaction fails.
"""
[docs]
class InvalidChild(ChainTransactionError):
"""
Attempting to set an invalid child for a hotkey on a network.
"""
[docs]
class NominationError(ChainTransactionError):
"""
Error raised when a nomination transaction fails.
"""
[docs]
class NonAssociatedColdKey(ChainTransactionError):
"""
Request to stake, unstake or subscribe is made by a coldkey that is not associated with the hotkey account.
"""
[docs]
class NotEnoughStakeToSetChildkeys(ChainTransactionError):
"""
The parent hotkey doesn't have enough own stake to set childkeys.
"""
[docs]
class NotRegisteredError(ChainTransactionError):
"""
Error raised when a neuron is not registered, and the transaction requires it to be.
"""
[docs]
class ProportionOverflow(ChainTransactionError):
"""
Proportion overflow when setting children.
"""
[docs]
class RegistrationError(ChainTransactionError):
"""
Error raised when a neuron registration transaction fails.
"""
[docs]
class RegistrationNotPermittedOnRootSubnet(ChainTransactionError):
"""
Operation is not permitted on the root subnet.
"""
[docs]
class StakeError(ChainTransactionError):
"""
Error raised when a stake transaction fails.
"""
[docs]
class NotDelegateError(StakeError):
"""
Error raised when a hotkey you are trying to stake to is not a delegate.
"""
[docs]
class SubNetworkDoesNotExist(ChainTransactionError):
"""
The subnet does not exist.
"""
[docs]
class TakeError(ChainTransactionError):
"""
Error raised when an increase / decrease take transaction fails.
"""
[docs]
class TransferError(ChainTransactionError):
"""
Error raised when a transfer transaction fails.
"""
[docs]
class TooManyChildren(ChainTransactionError):
"""
Too many children MAX 5.
"""
[docs]
class TxRateLimitExceeded(ChainTransactionError):
"""
Default transaction rate limit exceeded.
"""
[docs]
class DelegateTxRateLimitExceeded(TxRateLimitExceeded):
"""
A transactor exceeded the rate limit for delegate transaction.
"""
[docs]
class UnstakeError(ChainTransactionError):
"""
Error raised when an unstake transaction fails.
"""
[docs]
class ChainQueryError(ChainError):
"""
Error for any chain query related errors.
"""
[docs]
class InvalidRequestNameError(Exception):
"""This exception is raised when the request name is invalid. Usually indicates a broken URL."""
[docs]
class SynapseException(Exception):
def __init__(
self, message="Synapse Exception", synapse: Optional["Synapse"] = None
):
self.message = message
self.synapse = synapse
super().__init__(self.message)
[docs]
class UnknownSynapseError(SynapseException):
"""This exception is raised when the request name is not found in the Axon's forward_fns dictionary."""
[docs]
class SynapseParsingError(Exception):
"""This exception is raised when the request headers are unable to be parsed into the synapse type."""
[docs]
class NotVerifiedException(SynapseException):
"""This exception is raised when the request is not verified."""
[docs]
class BlacklistedException(SynapseException):
"""This exception is raised when the request is blacklisted."""
[docs]
class PriorityException(SynapseException):
"""This exception is raised when the request priority is not met."""
[docs]
class PostProcessException(SynapseException):
"""This exception is raised when the response headers cannot be updated."""
[docs]
class RunException(SynapseException):
"""This exception is raised when the requested function cannot be executed. Indicates a server error."""
[docs]
class InternalServerError(SynapseException):
"""This exception is raised when the requested function fails on the server. Indicates a server error."""
[docs]
class SynapseDendriteNoneException(SynapseException):
def __init__(
self,
message="Synapse Dendrite is None",
synapse: Optional["Synapse"] = None,
):
self.message = message
super().__init__(self.message, synapse)