Skip to content

Errors

matrix.py uses a structured exception hierarchy so you can catch errors at exactly the right level of specificity. All library exceptions inherit from MatrixError.

from matrix.errors import CommandNotFoundError, CooldownError

@bot.error
async def on_error(ctx, error):
    if isinstance(error, CooldownError):
        await ctx.reply(f"Slow down! Retry in {error.retry:.1f}s.")
    elif isinstance(error, CommandNotFoundError):
        await ctx.reply("Unknown command.")
    else:
        raise error

matrix.errors

Callback module-attribute

Callback = Callable[..., Coroutine[Any, Any, Any]]

MatrixError

Bases: Exception

RoomNotFoundError

Bases: MatrixError

RegistryError

Bases: MatrixError

AlreadyRegisteredError

AlreadyRegisteredError(entry)

Bases: RegistryError

Source code in matrix/errors.py
25
26
27
28
def __init__(self, entry: "Command | Group | Extension"):
    super().__init__(
        f"{entry.__class__.__name__} '{entry.name}' is already registered"
    )

CommandError

Bases: MatrixError

CommandNotFoundError

CommandNotFoundError(cmd)

Bases: CommandError

Source code in matrix/errors.py
36
37
def __init__(self, cmd: str):
    super().__init__(f"Command with name '{cmd}' not found")

CommandAlreadyRegisteredError

CommandAlreadyRegisteredError(cmd)

Bases: CommandError

Source code in matrix/errors.py
41
42
def __init__(self, cmd: "Command"):
    super().__init__(f"Command '{cmd}' is already registered")

MissingArgumentError

MissingArgumentError(param)

Bases: CommandError

Source code in matrix/errors.py
46
47
def __init__(self, param: inspect.Parameter):
    super().__init__(f"Missing required argument: '{param.name}'")

CheckError

CheckError(cmd, check)

Bases: CommandError

Source code in matrix/errors.py
51
52
def __init__(self, cmd: "Command", check: Callback):
    super().__init__(f"'{check.__name__}' has failed for '{cmd.name}'")

GroupError

Bases: CommandError

ConfigError

ConfigError(error)

Bases: MatrixError

Source code in matrix/errors.py
60
61
def __init__(self, error: str):
    super().__init__(f"Missing required configuration: '{error}'")

CooldownError

CooldownError(cmd, check, retry)

Bases: CheckError

Source code in matrix/errors.py
65
66
67
def __init__(self, cmd: "Command", check: Callback, retry: float):
    self.retry = retry
    super().__init__(cmd, check)

retry instance-attribute

retry = retry