DBusError

All facilities that return errors from remote methods (such as g_dbus_connection_call_sync()) use GError to represent both D-Bus errors (e.g. errors returned from the other peer) and locally in-process generated errors.

To check if a returned GError is an error from a remote peer, use g_dbus_error_is_remote_error(). To get the actual D-Bus error name, use g_dbus_error_get_remote_error(). Before presenting an error, always use g_dbus_error_strip_remote_error().

In addition, facilities used to return errors to a remote peer also use GError. See g_dbus_method_invocation_return_error() for discussion about how the D-Bus error name is set.

Applications can associate a GError error domain with a set of D-Bus errors in order to automatically map from D-Bus errors to GError and back. This is typically done in the function returning the GQuark for the error domain:

With this setup, a D-Bus peer can transparently pass e.g. FOO_BAR_ERROR_ANOTHER_ERROR and other peers will see the D-Bus error name org.project.Foo.Bar.Error.AnotherError.

If the other peer is using GDBus, and has registered the association with g_dbus_error_register_error_domain() in advance (e.g. by invoking the FOO_BAR_ERROR quark generation itself in the previous example) the peer will see also FOO_BAR_ERROR_ANOTHER_ERROR instead of G_IO_ERROR_DBUS_ERROR. Note that GDBus clients can still recover org.project.Foo.Bar.Error.AnotherError using g_dbus_error_get_remote_error().

Note that errors in the G_DBUS_ERROR error domain is intended only for returning errors from a remote message bus process. Errors generated locally in-process by e.g. GDBusConnection is from the G_IO_ERROR domain.

Constructors

this
this(GError* gError)

Sets our main struct and passes it to the parent class

this
this(string dbusErrorName, string dbusErrorMessage)

Creates a GError based on the contents of dbus_error_name and dbus_error_message. Errors registered with g_dbus_error_register_error() will be looked up using dbus_error_name and if a match is found, the error domain and code is used. Applications can use g_dbus_error_get_remote_error() to recover dbus_error_name. If a match against a registered error is not found and the D-Bus error name is in a form as returned by g_dbus_error_encode_gerror() the error domain and code encoded in the name is used to create the GError. Also, dbus_error_name is added to the error message such that it can be recovered with g_dbus_error_get_remote_error(). Otherwise, a GError with the error code G_IO_ERROR_DBUS_ERROR in the G_IO_ERROR error domain is returned. Also, dbus_error_name is added to the error message such that it can be recovered with g_dbus_error_get_remote_error(). In all three cases, dbus_error_name can always be recovered from the returned GError using the g_dbus_error_get_remote_error() function (unless g_dbus_error_strip_remote_error() hasn't been used on the returned error). This function is typically only used in object mappings to prepare GError instances for applications. Regular applications should not use it. Since 2.26

Members

Functions

encodeGerror
string encodeGerror()

Creates a D-Bus error name to use for error. If error matches a registered error (cf. g_dbus_error_register_error()), the corresponding D-Bus error name will be returned. Otherwise the a name of the form org.gtk.GDBus.UnmappedGError.Quark._ESCAPED_QUARK_NAME.Code_ERROR_CODE will be used. This allows other GDBus applications to map the error on the wire back to a GError using g_dbus_error_new_for_dbus_error(). This function is typically only used in object mappings to put a GError on the wire. Regular applications should not use it. Since 2.26

getDBusErrorStruct
GError* getDBusErrorStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getRemoteError
string getRemoteError()

Gets the D-Bus error name used for error, if any. This function is guaranteed to return a D-Bus error name for all GErrors returned from functions handling remote method calls (e.g. g_dbus_connection_call_finish()) unless g_dbus_error_strip_remote_error() has been used on error. Since 2.26

getStruct
void* getStruct()

the main Gtk struct as a void*

isRemoteError
int isRemoteError()

Checks if error represents an error received via D-Bus from a remote peer. If so, use g_dbus_error_get_remote_error() to get the name of the error. Since 2.26

stripRemoteError
int stripRemoteError()

Looks for extra information in the error message used to recover the D-Bus error name and strips it if found. If stripped, the message field in error will correspond exactly to what was received on the wire. This is typically used when presenting errors to the end user. Since 2.26

Static functions

registerError
int registerError(GQuark errorDomain, int errorCode, string dbusErrorName)

Creates an association to map between dbus_error_name and GErrors specified by error_domain and error_code. This is typically done in the routine that returns the GQuark for an error domain. Since 2.26

registerErrorDomain
void registerErrorDomain(string errorDomainQuarkName, gsize quarkVolatile, GDBusErrorEntry[] entries)

Helper function for associating a GError error domain with D-Bus error names. Since 2.26

setDbusErrorValist
void setDbusErrorValist(ErrorG error, string dbusErrorName, string dbusErrorMessage, string format, void* varArgs)

Like g_dbus_error_set_dbus_error() but intended for language bindings. Since 2.26

unregisterError
int unregisterError(GQuark errorDomain, int errorCode, string dbusErrorName)

Destroys an association previously set up with g_dbus_error_register_error(). Since 2.26

Variables

gError
GError* gError;

the main Gtk struct

Meta