After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 662396 - Need to register errors before translating errors received on the wire
Need to register errors before translating errors received on the wire
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: gdbus
2.28.x
Other Linux
: Normal normal
: ---
Assigned To: David Zeuthen (not reading bugmail)
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-10-21 16:11 UTC by David Woodhouse
Modified: 2018-05-24 13:28 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description David Woodhouse 2011-10-21 16:11:28 UTC
I have followed the instructions at
http://developer.gnome.org/gio/2.29/GDBusError.html#error-registration

I use GDBus to make a method call, which returns an error like org.project.Foo.Bar.Error.Failed.

I inspect the resulting GError, and check for error->domain == FOO_BAR_ERROR && error->code == FOO_BAR_ERROR_FAILED.

But the comparison *fails*, the first time I do this.

This is because my *comparison* is the first time that FOO_BAR_ERROR is evaluated and the foo_bar_error_quark() function is called. The errors weren't *registered* for translation until the first comparison.

By adding a "dummy" call to foo_bar_error_quark() in my code before making the GDBus call, I can make things work properly.

I can't see a nice way to *fix* this without C++ initialisers, but at least we could document it properly. The above-referenced documentation says nothing about this issue.
Comment 1 David Zeuthen (not reading bugmail) 2011-10-21 17:01:23 UTC
(In reply to comment #0)
> I can't see a nice way to *fix* this without C++ initialisers, 

GCC has _attribute ((constructor)) and other compilers / binary formats has similar features. See e.g. http://people.freedesktop.org/~david/c++-like-constructors-in-c.c.txt ... Other (better?) approaches include registering the errors

 - in the get_gtype(), init() or class_init() function for
   "anchor/context" types (e.g. a type you know users of
   your library will instantiate ... for example GUdevClient
   or GVolumeManager); or

 - if your library has an init function, do it there (but I
   generally recommend against init() functions)

 - in GDBusProxy-derived classes ... for example, we could add
   a feature to gdbus-codegen(1) so it will call one or more
   init() functions of your choice before doing any method calls

But, yeah, it's generally a hard problem.

> but at least we
> could document it properly. The above-referenced documentation says nothing
> about this issue.

It's sorta implicit in the docs here

 http://developer.gnome.org/gio/unstable/gio-GDBusError.html#g-dbus-error-new-for-dbus-error

But, sure, I don't mind adding a comment explicitly stating this is needed and the four approaches above.
Comment 2 David Zeuthen (not reading bugmail) 2011-10-25 17:31:31 UTC
Somewhat related: bug 662693 comment 1 for a proposal to make gdbus-codegen(1) generate GError error domains for D-Bus errors.
Comment 3 David Zeuthen (not reading bugmail) 2011-10-25 17:33:23 UTC
Updating summary to be more accurate.
Comment 4 GNOME Infrastructure Team 2018-05-24 13:28:28 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/469.