Skip to content

risa.errors

The exceptions risa raises.

Every exception derives from RisaError, builds its own message, and keeps the details it was raised with as attributes, so callers can branch on fields instead of parsing the message.

AlreadyRespondedError

AlreadyRespondedError(attempted: str, already_sent: str)

Bases: RisaError

Raised when an interaction that already has its initial response is deferred.

Attributes:

  • attempted (str) –

    What was attempted.

  • already_sent (str) –

    The initial response the interaction already received.

ArgBindError

ArgBindError(callback_name: str, parameter: str | None, reason: str)

Bases: RisaError

Raised when risa.bind gets arguments the handler cannot carry on the wire.

Attributes:

  • callback_name (str) –

    The qualified name of the handler.

  • parameter (str | None) –

    The parameter at fault, or None when the arguments as a whole do not fit.

  • reason (str) –

    What is wrong with them.

CodecUnavailableError

CodecUnavailableError(codec_name: str, extra: str)

Bases: RisaError

Raised when a codec needs an optional dependency that is not installed.

Attributes:

  • codec_name (str) –

    The codec that is unavailable.

  • extra (str) –

    The hikari-risa extra that installs it.

CustomIdOverflowError

CustomIdOverflowError(view_name: str, length: int)

Bases: RisaError

Raised when a component's custom_id would exceed Discord's limit.

Attributes:

  • view_name (str) –

    The view the component belongs to.

  • length (int) –

    The length the custom_id would have.

DuplicateHandlerError

DuplicateHandlerError(
    view_name: str,
    token: str,
    *,
    first_id: str,
    first_version: int,
    second_id: str,
    second_version: int,
)

Bases: RisaError

Raised when two handlers of one view would route under the same token.

Attributes:

  • view_name (str) –

    The view both handlers belong to.

  • token (str) –

    The token both handlers hash to.

  • first_id (str) –

    The id of the first handler.

  • first_version (int) –

    The version of the first handler.

  • second_id (str) –

    The id of the second handler.

  • second_version (int) –

    The version of the second handler.

DuplicateViewError

DuplicateViewError(view_name: str, existing_name: str, cookie: str)

Bases: RisaError

Raised when two views would route under the same cookie.

Attributes:

  • view_name (str) –

    The view being registered.

  • existing_name (str) –

    The view already registered under that cookie.

  • cookie (str) –

    The cookie both views hash to.

EphemeralOriginError

EphemeralOriginError(view_name: str)

Bases: RisaError

Raised when an ephemeral origin message can no longer be edited.

On an ephemeral view, rerender() and edit() must be the initial response, or follow a silent defer().

Attributes:

  • view_name (str) –

    The view whose message could not be edited.

HandlerNotCallableError

HandlerNotCallableError(callback_name: str)

Bases: RisaError

Raised when a handler is called directly instead of being dispatched by risa.

Attributes:

  • callback_name (str) –

    The qualified name of the handler.

HandlerSignatureError

HandlerSignatureError(callback_name: str, parameter: str, reason: str)

Bases: RisaError

Raised at registration when a handler's parameters cannot be routed.

Attributes:

  • callback_name (str) –

    The qualified name of the handler.

  • parameter (str) –

    The parameter at fault.

  • reason (str) –

    What is wrong with it.

LayoutError

LayoutError(path: str, reason: str)

Bases: RisaError

Raised when a layout cannot be built.

Attributes:

  • path (str) –

    Where in the tree the problem is, such as Container > Row[1] > Button[0].

  • reason (str) –

    What is wrong there.

LockTimeoutError

LockTimeoutError(key: str, timeout: float)

Bases: StateError

Raised when the lock on a view's state is not granted in time.

Attributes:

  • key (str) –

    The store key of the state.

  • timeout (float) –

    How long risa waited, in seconds.

NoViewError

NoViewError(view_name: str, attempted: str)

Bases: RisaError

Raised when an operation needs the view's state, but the context has none.

That is the case in on_outdated and on_state_missing, after ctx.replace gave the message to another view, and in a context kept past the end of its dispatch.

Attributes:

  • view_name (str) –

    The view the context belongs to.

  • attempted (str) –

    The operation that needed the state.

NotAHandlerError

NotAHandlerError(type_name: str)

Bases: RisaError

Raised when a component is given something that is not a risa handler.

Attributes:

  • type_name (str) –

    The type of the object that was given.

NotAViewError

NotAViewError(type_name: str)

Bases: RisaError

Raised when a class or instance that was never @risa.register-ed is used as a view.

Attributes:

  • type_name (str) –

    The type that was given.

RisaError

Bases: Exception

Base class of every exception risa raises.

SerializationError

Bases: RisaError

Base class of the errors raised while writing or reading view state.

SignatureMismatchError

SignatureMismatchError(
    view_name: str, handler_id: str, version: int, *, found: str, expected: str
)

Bases: RisaError

Logged, not raised, when a click carries wire arguments for another handler signature.

The handler's wire parameters changed without a version bump. risa logs this error and routes the click to View.on_outdated. Bump the version in @risa.handler(version=...) so the old components are retired instead.

Attributes:

  • view_name (str) –

    The view the handler belongs to.

  • handler_id (str) –

    The handler's id.

  • version (int) –

    The handler's version.

  • found (str) –

    The fingerprint the component carries.

  • expected (str) –

    The fingerprint of the handler's current signature.

StateConflictError

StateConflictError(key: str, *, expected: int, found: int)

Bases: StateError

Raised when another process wrote a view's state first.

By the time it is raised, the view already holds the state that won, so the handler can apply its change again on top of it. A record that cannot be read raises StateUnreadableError instead.

Attributes:

  • key (str) –

    The store key of the state.

  • expected (int) –

    The version this dispatch read.

  • found (int) –

    The version the store holds.

StateEncodeError

StateEncodeError(view_name: str, field: str, reason: str)

Bases: SerializationError

Raised when a durable field holds a value that cannot be serialized.

Attributes:

  • view_name (str) –

    The view the field belongs to.

  • field (str) –

    The field at fault.

  • reason (str) –

    Why its value cannot be written.

StateError

Bases: RisaError

Base class of the errors raised while working with InStore state.

StateNotFoundError

StateNotFoundError(key: str)

Bases: StateError

Raised when a view's stored state is gone in the middle of a dispatch.

Attributes:

  • key (str) –

    The store key of the state.

StateOverflowError

StateOverflowError(
    view_name: str,
    *,
    needed: int,
    available: int,
    slots: int,
    codec_name: str,
    fields: Mapping[str, int] | None = None,
)

Bases: RisaError

Raised when an InMessage view's durable state does not fit its components.

Attributes:

  • view_name (str) –

    The view whose state overflowed.

  • needed (int) –

    The bytes of state to write.

  • available (int) –

    The bytes the rendered components can carry.

  • slots (int) –

    The number of interactive components.

  • codec_name (str) –

    The codec the state was written with.

  • fields (Mapping[str, int]) –

    The bytes each durable field takes, by name, in declaration order. What they leave of needed is risa's own framing.

StateUnreadableError

StateUnreadableError(key: str)

Bases: StateError

Raised when another process wrote a view's state first, in a form this code cannot read.

It can happen during a deploy, when a process with other fields wins the race. The view keeps its own state, the change is lost, and another attempt in this click raises again.

Attributes:

  • key (str) –

    The store key of the state.

StoreConformanceError

StoreConformanceError(failures: Sequence[str])

Bases: RisaError

Raised by risa.store.testing.verify_store when a store fails any check.

Attributes:

  • failures (Sequence[str]) –

    One line per failed check, naming the check and what went wrong.

StoreUnavailableError

StoreUnavailableError(key: str, reason: str)

Bases: StateError

Raised when the store holding a view's state cannot be reached.

The state is not lost; it only cannot be read or written right now. A store reports missing state by returning nothing, never with this error.

Attributes:

  • key (str) –

    The store key of the state.

  • reason (str) –

    What went wrong.

ViewDeclarationError

ViewDeclarationError(view_name: str, reason: str)

Bases: RisaError

Raised when a view is declared or added in a way risa cannot serve.

Attributes:

  • view_name (str) –

    The view at fault.

  • reason (str) –

    What is wrong with it.