Top |
Functions
Description
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
// foo-bar-error.h: #define FOO_BAR_ERROR (foo_bar_error_quark ()) GQuark foo_bar_error_quark (void); typedef enum { FOO_BAR_ERROR_FAILED, FOO_BAR_ERROR_ANOTHER_ERROR, FOO_BAR_ERROR_SOME_THIRD_ERROR, FOO_BAR_N_ERRORS / *< skip >* / } FooBarError; // foo-bar-error.c: static const GDBusErrorEntry foo_bar_error_entries[] = { {FOO_BAR_ERROR_FAILED, "org.project.Foo.Bar.Error.Failed"}, {FOO_BAR_ERROR_ANOTHER_ERROR, "org.project.Foo.Bar.Error.AnotherError"}, {FOO_BAR_ERROR_SOME_THIRD_ERROR, "org.project.Foo.Bar.Error.SomeThirdError"}, }; // Ensure that every error code has an associated D-Bus error name G_STATIC_ASSERT (G_N_ELEMENTS (foo_bar_error_entries) == FOO_BAR_N_ERRORS); GQuark foo_bar_error_quark (void) { static volatile gsize quark_volatile = 0; g_dbus_error_register_error_domain ("foo-bar-error-quark", &quark_volatile, foo_bar_error_entries, G_N_ELEMENTS (foo_bar_error_entries)); return (GQuark) quark_volatile; } |
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.
Functions
g_dbus_error_is_remote_error ()
gboolean
g_dbus_error_is_remote_error (const GError *error
);
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
g_dbus_error_get_remote_error ()
gchar *
g_dbus_error_get_remote_error (const GError *error
);
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
g_dbus_error_strip_remote_error ()
gboolean
g_dbus_error_strip_remote_error (GError *error
);
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
g_dbus_error_register_error_domain ()
void g_dbus_error_register_error_domain (const gchar *error_domain_quark_name
,volatile gsize *quark_volatile
,const GDBusErrorEntry *entries
,guint num_entries
);
Helper function for associating a GError error domain with D-Bus error names.
Parameters
error_domain_quark_name |
The error domain name. |
|
quark_volatile |
A pointer where to store the GQuark. |
|
entries |
A pointer to |
|
num_entries |
Number of items to register. |
Since 2.26
g_dbus_error_register_error ()
gboolean g_dbus_error_register_error (GQuark error_domain
,gint error_code
,const gchar *dbus_error_name
);
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.
Parameters
error_domain |
A GQuark for a error domain. |
|
error_code |
An error code. |
|
dbus_error_name |
A D-Bus error name. |
Since 2.26
g_dbus_error_unregister_error ()
gboolean g_dbus_error_unregister_error (GQuark error_domain
,gint error_code
,const gchar *dbus_error_name
);
Destroys an association previously set up with g_dbus_error_register_error()
.
Parameters
error_domain |
A GQuark for a error domain. |
|
error_code |
An error code. |
|
dbus_error_name |
A D-Bus error name. |
Since 2.26
g_dbus_error_new_for_dbus_error ()
GError * g_dbus_error_new_for_dbus_error (const gchar *dbus_error_name
,const gchar *dbus_error_message
);
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
g_dbus_error_set_dbus_error ()
void g_dbus_error_set_dbus_error (GError **error
,const gchar *dbus_error_name
,const gchar *dbus_error_message
,const gchar *format
,...
);
Does nothing if error
is NULL
. Otherwise sets *error
to
a new GError created with g_dbus_error_new_for_dbus_error()
with dbus_error_message
prepend with format
(unless NULL
).
Since 2.26
g_dbus_error_set_dbus_error_valist ()
void g_dbus_error_set_dbus_error_valist (GError **error
,const gchar *dbus_error_name
,const gchar *dbus_error_message
,const gchar *format
,va_list var_args
);
Like g_dbus_error_set_dbus_error()
but intended for language bindings.
Since 2.26
g_dbus_error_encode_gerror ()
gchar *
g_dbus_error_encode_gerror (const GError *error
);
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
Types and Values
enum GDBusError
Error codes for the G_DBUS_ERROR
error domain.
Members
A generic error; "something went wrong" - see the error message for more. |
||
There was not enough memory to complete an operation. |
||
The bus doesn't know how to launch a service to supply the bus name you wanted. |
||
The bus name you referenced doesn't exist (i.e. no application owns it). |
||
No reply to a message expecting one, usually means a timeout occurred. |
||
Something went wrong reading or writing to a socket, for example. |
||
A D-Bus bus address was malformed. |
||
Requested operation isn't supported (like ENOSYS on UNIX). |
||
Some limited resource is exhausted. |
||
Security restrictions don't allow doing what you're trying to do. |
||
Authentication didn't work. |
||
Unable to connect to server (probably caused by ECONNREFUSED on a socket). |
||
Certain timeout errors, possibly ETIMEDOUT on a socket. Note that
|
||
No network access (probably ENETUNREACH on a socket). |
||
Can't bind a socket since its address is in use (i.e. EADDRINUSE). |
||
The connection is disconnected and you're trying to use it. |
||
Invalid arguments passed to a method call. |
||
Missing file. |
||
Existing file and the operation you're using does not silently overwrite. |
||
Method name you invoked isn't known by the object you invoked it on. |
||
Certain timeout errors, e.g. while starting a service. Warning: this is
confusingly-named given that |
||
Tried to remove or modify a match rule that didn't exist. |
||
The match rule isn't syntactically valid. |
||
While starting a new process, the |
||
While starting a new process, the |
||
While starting a new process, the child exited with a status code. |
||
While starting a new process, the child exited on a signal. |
||
While starting a new process, something went wrong. |
||
We failed to setup the environment correctly. |
||
We failed to setup the config parser correctly. |
||
Bus name was not valid. |
||
Service file not found in system-services directory. |
||
Permissions are incorrect on the setuid helper. |
||
Service file invalid (Name, User or Exec missing). |
||
Tried to get a UNIX process ID and it wasn't available. |
||
Tried to get a UNIX process ID and it wasn't available. |
||
A type signature is not valid. |
||
A file contains invalid syntax or is otherwise broken. |
||
Asked for SELinux security context and it wasn't available. |
||
Asked for ADT audit data and it wasn't available. |
||
There's already an object with the requested object path. |
||
Object you invoked a method on isn't known. Since 2.42 |
||
Interface you invoked a method on isn't known by the object. Since 2.42 |
||
Property you tried to access isn't known by the object. Since 2.42 |
||
Property you tried to set is read-only. Since 2.42 |
Since 2.26
G_DBUS_ERROR
#define G_DBUS_ERROR g_dbus_error_quark()
Error domain for errors generated by a remote message bus. Errors in this domain will be from the GDBusError enumeration. See GError for more information on error domains.
Note that errors in this 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.
Since 2.26
GDBusErrorEntry
typedef struct { gint error_code; const gchar *dbus_error_name; } GDBusErrorEntry;
Struct used in g_dbus_error_register_error_domain()
.
Since 2.26