[systemd-devel] sdbus errors and their underlaying int value: unique?

Simon McVittie smcv at collabora.com
Wed Mar 3 19:52:50 UTC 2021


On Wed, 03 Mar 2021 at 13:51:38 +0100, Lennart Poettering wrote:
> On Di, 02.03.21 10:40, Carlo Wood (carlo at alinoe.com) wrote:
> > In C++ we have std::error_code which stores both a (unique) domain
> > and an int that is defined within that domain. The integer values
> > do not have to be globally unique.
>
> Generally: when doing D-Bus focus on the error names, because that's
> the native thing.

It seems std::error_code is conceptually the same as the domain and code
from GLib's GError (convergent evolution, or inspiration from GLib?),
so it would probably be useful to look at how GLib's GDBus maps GError
to/from D-Bus errors:
https://developer.gnome.org/gio/stable/gio-GDBusError.html

In GError, the domain is basically a string (it's a GQuark, which is a
handle representing an "interned" string), the code is an int defined
within that domain, and there is also a human-readable message. So for
instance, org.freedesktop.DBus.Error.NoMemory maps to
(domain=G_DBUS_ERROR, code=G_DBUS_ERROR_NO_MEMORY), which behind the
scenes is the same as
(domain=g_quark_from_string("g-dbus-error-quark"), code=1).

    smcv


More information about the systemd-devel mailing list