Exceptions

Error name bound exceptions

These exceptions are bound to specific D-Bus error names. For example, DbusFailedError is bound to org.freedesktop.DBus.Error.Failed error name.

This means if the remote object sends an error message with this error name the Python will receive this exception.

When raised in a method callback an error message will be sent back to caller.

See list of error exceptions.

New error bound exceptions

If you want to create a new error bound exception you should subclass it from DbusFailedError and provide a unique dbus_error_name attribute in the exception body definition.

Example:

class DbusExampleError(DbusFailedError):
    dbus_error_name = 'org.example.Error'

If dbus_error_name is not unique the ValueError will be raised.

Defining an exception will automatically bind incoming error message to this new exception.

Existing exceptions can be manually binded using map_exception_to_dbus_error() function.

Python built-in exceptions

All Python built-in exceptions are mapped to D-Bus errors.

The D-Bus error name is created by appending org.python.Error. to the exception name.

For example, AssertionError is bound to org.python.Error.AssertionError name.

Functions

sdbus.exceptions.map_exception_to_dbus_error(exception, dbus_error_name)

Map exception to a D-bus error. Error name must be unique.

Parameters:
  • exception (Type[Exception]) – Exception to bind.

  • dbus_error_name (str) – D-Bus error name to bind to.

Other exceptions

exception sdbus.exceptions.SdBusBaseError

Base exceptions for all exceptions defined in sdbus.

exception sdbus.exceptions.SdBusUnmappedMessageError

Message error that is unmapped.

The exceptions argument is a tuple of error name and error message.

exception sdbus.exceptions.SdBusLibraryError

sd-bus library returned error.

Exception message contains line number and the error name.

Name request exceptions

These exceptions will be raise if an error related to ownership of D-Bus names occurs when calling request_default_bus_name_async() or request_default_bus_name().

exception sdbus.exceptions.SdBusRequestNameError

Common base exception for any name ownership error.

exception sdbus.exceptions.SdBusRequestNameInQueueError

Someone already owns the name but the request has been placed in queue.

exception sdbus.exceptions.SdBusRequestNameExistsError

Someone already owns the name.

exception sdbus.exceptions.SdBusRequestNameAlreadyOwnerError

The caller already owns the name.

Error name exception list

exception sdbus.exceptions.DbusFailedError

Generic failure exception.

Recommended to subclass to create a new exception.

dbus_error_name: str = org.freedesktop.DBus.Error.Failed
exception sdbus.exceptions.DbusNoMemoryError

Remote object is out of memory.

dbus_error_name: str = org.freedesktop.DBus.Error.NoMemory
exception sdbus.exceptions.DbusServiceUnknownError

No service with such name exists.

Probably should only be raised by bus daemon.

dbus_error_name: str = org.freedesktop.DBus.Error.ServiceUnknown
exception sdbus.exceptions.DbusNameHasNoOwnerError

No process owns the name you called.

Probably should only be raised by bus daemon.

dbus_error_name: str = org.freedesktop.DBus.Error.NameHasNoOwner
exception sdbus.exceptions.DbusNoReplyError

Timeout on reply.

dbus_error_name: str = org.freedesktop.DBus.Error.NoReply
exception sdbus.exceptions.DbusIOError

Input/Output error.

dbus_error_name: str = org.freedesktop.DBus.Error.IOError
exception sdbus.exceptions.DbusBadAddressError

Bad address.

dbus_error_name: str = org.freedesktop.DBus.Error.BadAddress
exception sdbus.exceptions.DbusNotSupportedError

Something is unsupported on this platform.

dbus_error_name: str = org.freedesktop.DBus.Error.NotSupported
exception sdbus.exceptions.DbusLimitsExceededError

Some resource was exhausted. (for example, file descriptors)

dbus_error_name: str = org.freedesktop.DBus.Error.LimitsExceeded
exception sdbus.exceptions.DbusAccessDeniedError

Caller does not have enough privileges.

dbus_error_name: str = org.freedesktop.DBus.Error.AccessDenied
exception sdbus.exceptions.DbusAuthFailedError

Authentication failed.

dbus_error_name: str = org.freedesktop.DBus.Error.AuthFailed
exception sdbus.exceptions.DbusNoServerError

Unable to connect to bus.

dbus_error_name: str = org.freedesktop.DBus.Error.NoServer
exception sdbus.exceptions.DbusTimeoutError

Socket timeout.

This is different from DbusNoReplyError as here the connection to bus timeout not the remote object not replying.

dbus_error_name: str = org.freedesktop.DBus.Error.Timeout
exception sdbus.exceptions.DbusNoNetworkError

No network access.

Encountered you use D-Bus over TCP or SSH.

dbus_error_name: str = org.freedesktop.DBus.Error.NoNetwork
exception sdbus.exceptions.DbusAddressInUseError

Address in use.

dbus_error_name: str = org.freedesktop.DBus.Error.AddressInUse
exception sdbus.exceptions.DbusDisconnectedError

Disconnected from bus.

dbus_error_name: str = org.freedesktop.DBus.Error.Disconnected
exception sdbus.exceptions.DbusInvalidArgsError

Method call args are invalid.

dbus_error_name: str = org.freedesktop.DBus.Error.InvalidArgs
exception sdbus.exceptions.DbusFileNotFoundError

File not found.

dbus_error_name: str = org.freedesktop.DBus.Error.FileNotFound
exception sdbus.exceptions.DbusFileExistsError

Generic failure exception.

Recommended to subclass to create a new exception.

dbus_error_name: str = org.freedesktop.DBus.Error.FileExists
exception sdbus.exceptions.DbusUnknownMethodError

Unknown D-Bus method.

dbus_error_name: str = org.freedesktop.DBus.Error.UnknownMethod
exception sdbus.exceptions.DbusUnknownObjectError

Unknown D-Bus object.

dbus_error_name: str = org.freedesktop.DBus.Error.UnknownObject
exception sdbus.exceptions.DbusUnknownInterfaceError

Unknown D-Bus interface.

dbus_error_name: str = org.freedesktop.DBus.Error.UnknownInterface
exception sdbus.exceptions.DbusUnknownPropertyError

Unknown D-Bus property.

dbus_error_name: str = org.freedesktop.DBus.Error.UnknownProperty
exception sdbus.exceptions.DbusPropertyReadOnlyError

D-Bus property is read only.

dbus_error_name: str = org.freedesktop.DBus.Error.PropertyReadOnly
exception sdbus.exceptions.DbusUnixProcessIdUnknownError

PID does not exists.

dbus_error_name: str = org.freedesktop.DBus.Error.UnixProcessIdUnknown
exception sdbus.exceptions.DbusInvalidSignatureError

Invalid D-Bus type signature.

dbus_error_name: str = org.freedesktop.DBus.Error.InvalidSignature
exception sdbus.exceptions.DbusInvalidFileContentError

Invalid file content.

dbus_error_name: str = org.freedesktop.DBus.Error.InvalidFileContent
exception sdbus.exceptions.DbusInconsistentMessageError

D-Bus message is malformed.

dbus_error_name: str = org.freedesktop.DBus.Error.InconsistentMessage
exception sdbus.exceptions.DbusMatchRuleNotFound

Match rule does not exist.

dbus_error_name: str = org.freedesktop.DBus.Error.MatchRuleNotFound
exception sdbus.exceptions.DbusMatchRuleInvalidError

Match rule is invalid.

dbus_error_name: str = org.freedesktop.DBus.Error.MatchRuleInvalid
exception sdbus.exceptions.DbusInteractiveAuthorizationRequiredError

Requires interactive authorization.

dbus_error_name: str = org.freedesktop.DBus.Error.InteractiveAuthorizationRequired