Skip to content

Error Handling ABCs#

HasErrorHandler #

Bases: ABC, Generic[ClientT]

A trait for objects that can have an error handler set on them.

error_handler abstractmethod property writable #

error_handler: ErrorHandlerCallbackT[ClientT] | None

The error handler for this object.

set_error_handler #

set_error_handler(
    callback: ErrorHandlerCallbackT[ClientT] | None = None,
) -> (
    ErrorHandlerCallbackT[ClientT]
    | Callable[[ErrorHandlerCallbackT[ClientT]], ErrorHandlerCallbackT[ClientT]]
)

Decorator to set an error handler for this object. This can be added to commands, groups, or plugins.

This function will be called when an exception is raised during the invocation of a command.

Example
@client.include
@arc.slash_command("foo", "Foo command description")
async def foo(ctx: arc.GatewayContext) -> None:
    raise RuntimeError("foo")

@foo.set_error_handler
async def foo_error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
    if isinstance(exc, RuntimeError):
        await ctx.respond("foo failed")
        return

    raise exc

Warning

Errors that cannot be handled by the error handler should be re-raised. Otherwise they will not propagate to the next error handler.