Skip to content

Exceptions

NioBotException

Bases: Exception

Base exception for NioBot.

Warning

In some rare cases, all of exception, response and original may be None.

All other exceptions raised by this library will subclass this exception, so at least all the below are always available:

Attributes:

Name Type Description
message Optional[str]

A simple humanised explanation of the issue, if available.

response Optional[ErrorResponse]

The response object from the server, if available.

exception Optional[Union[ErrorResponse, BaseException]]

The exception that was raised, if available.

original Union[ErrorResponse, BaseException, None]

The original response, or exception if response was not available.

bottom_of_chain

bottom_of_chain(
    other: Optional[Union[Exception, ErrorResponse]] = None
) -> Union[BaseException, ErrorResponse]

Recursively checks the original attribute of the exception until it reaches the bottom of the chain.

This function finds you the absolute first exception that was raised.

Parameters:

Name Type Description Default
other Optional[Union[Exception, ErrorResponse]]

The other exception to recurse down. If None, defaults to the exception this method is called on.

None

Returns:

Type Description
Union[BaseException, ErrorResponse]

The bottom of the chain exception.

__str__

__str__() -> str

Returns a human-readable version of the exception.

__repr__

__repr__() -> str

Returns a developer-readable version of the exception.

GenericMatrixError

Bases: NioBotException

Exception for generic matrix errors where a valid response was expected, but got an ErrorResponse instead.

MessageException

Bases: NioBotException

Exception for message-related errors.

LoginException

Bases: NioBotException

Exception for login-related errors.

MediaException

Bases: MessageException

Exception for media-related errors.

MediaUploadException

Bases: MediaException

Exception for media-uploading related errors

MediaDownloadException

Bases: MediaException

Exception for media-downloading related errors

MediaCodecWarning

Bases: ResourceWarning

Warning that is dispatched when a media file is not in a supported codec.

You can filter this warning by using warnings.filterwarnings("ignore", category=niobot.MediaCodecWarning)

Often times, matrix clients are web-based, so they're limited to what the browser can display. This is usually:

  • h264/vp8/vp9/av1/theora video
  • aac/opus/vorbis/mp3/pcm_* audio
  • jpg/png/webp/avif/gif images

MetadataDetectionException

Bases: MediaException

Exception raised when metadata detection fails. Most of the time, this is an ffmpeg-related error

CommandError

Bases: NioBotException

Exception subclass for all command invocation related errors.

CommandNotFoundError

Bases: CommandError

Exception raised when a command is not found.

CommandPreparationError

Bases: CommandError

Exception subclass for errors raised while preparing a command for execution.

CommandDisabledError

Bases: CommandPreparationError

Exception raised when a command is disabled.

CommandArgumentsError

Bases: CommandPreparationError

Exception subclass for command argument related errors.

CommandParserError

Bases: CommandArgumentsError

Exception raised when there is an error parsing arguments.

CheckFailure

Bases: CommandPreparationError

Exception raised when a generic check call fails.

You should prefer one of the subclass errors over this generic one, or a custom subclass.

CheckFailure is often raised by the built-in checker when a check returns a falsy value without raising an error.

NotOwner

Bases: CheckFailure

Exception raised when the command invoker is not the owner of the bot.

InsufficientPower

Bases: CheckFailure

Exception raised when the command invoker does not have enough power to run the command.

NotADirectRoom

Bases: CheckFailure

Exception raised when the current room is not m.direct (a DM room)