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 639834 - GI does not make use of GObject.GError; instead RuntimeError is thrown whenever a GError is returned from a C function.
GI does not make use of GObject.GError; instead RuntimeError is thrown whenev...
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-01-18 10:55 UTC by Laszlo Pandy
Modified: 2011-01-19 17:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Convert GErrors to GObject.GError exceptions, and throw them upon returning from calling the C function. (3.34 KB, patch)
2011-01-18 10:55 UTC, Laszlo Pandy
needs-work Details | Review
Add GIMarshallingTests function which sets a GError, to test exception handling in bindings. (1.88 KB, patch)
2011-01-19 16:34 UTC, Laszlo Pandy
none Details | Review
Convert GErrors to GObject.GError exceptions, and throw them upon returning from calling the C function. (2.56 KB, patch)
2011-01-19 16:48 UTC, Laszlo Pandy
none Details | Review
Convert GErrors to GObject.GError exceptions, and throw them upon returning from calling the C function. (3.02 KB, patch)
2011-01-19 16:59 UTC, Laszlo Pandy
needs-work Details | Review
Convert GErrors to GObject.GError exceptions, and throw them upon returning from calling the C function. (3.03 KB, patch)
2011-01-19 17:21 UTC, Laszlo Pandy
none Details | Review

Description Laszlo Pandy 2011-01-18 10:55:49 UTC
When a wrapped C function returns a GError, currently GI throws a RuntimeError with the string message, not a GObject.GError exception. Also, the domain and GError enum code are discarded. This prevents Python developers from catching only GErrors (instead of all RuntimeErrors) and differentiating between the different GError domains.
Comment 1 Laszlo Pandy 2011-01-18 10:55:51 UTC
Created attachment 178614 [details] [review]
Convert GErrors to GObject.GError exceptions, and throw them upon returning from calling the C function.

This changes gi to make use of pyg_error_check() which already exists in pygobject.
The included tests check that the right error domain and code are returned for two Gtk C functions.
Comment 2 Simon van der Linden 2011-01-18 11:31:55 UTC
Review of attachment 178614 [details] [review]:

Almost OK for the call to pyg_error_check, but tests should not depend on GLib and Gtk.

::: gi/pygi-invoke.c
@@ +606,3 @@
     if (!retval) {
         g_assert (error != NULL);
+        pyg_error_check(&error);

The documentation of pyg_error_check reads "Deprecated: Since 2.16, use pyglib_error_check instead."

@@ +623,1 @@
             g_error_free (*error);

pyglib_error_check checks for *error != NULL and calls g_error_free for you, so you can remove this and use the return value for the next instructions in this block.

::: tests/test_gi.py
@@ +12,3 @@
 
+from gi.repository import Gtk
+from gi.repository import GLib

The tests should not depend on Gtk or GLib. Add the stuff needed to GIMarshallingTests instead.
Comment 3 Laszlo Pandy 2011-01-19 16:34:18 UTC
Created attachment 178748 [details] [review]
Add GIMarshallingTests function which sets a GError, to test exception handling in bindings.
Comment 4 Laszlo Pandy 2011-01-19 16:48:17 UTC
Created attachment 178751 [details] [review]
Convert GErrors to GObject.GError exceptions, and throw them upon returning from calling the C function.

This changes gi to make use of pyglib_error_check() which already exists in pyglib, but pygi must be changed to link to pyglib for it to work.

The included tests make use of the other patch attached to this bug, to check that the right exception is thrown from the new function in GIMarshallingTests.
two Gtk C functions.
Comment 5 Laszlo Pandy 2011-01-19 16:59:38 UTC
Created attachment 178752 [details] [review]
Convert GErrors to GObject.GError exceptions, and throw them upon returning from calling the C function.

This changes gi to make use of pyglib_error_check() which already exists in pyglib.

The included tests make use of the other patch attached to this bug, to check that the right exception is thrown from the new function in GIMarshallingTests.
two Gtk C functions.
Comment 6 Simon van der Linden 2011-01-19 17:10:44 UTC
Review of attachment 178752 [details] [review]:

::: tests/test_gi.py
@@ +1451,3 @@
+            self.assertEquals(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
+            self.assertEquals(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
+            self.assertEquals(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)

hum, you need to check that an exception is actually thrown; it might not.
Comment 7 Laszlo Pandy 2011-01-19 17:21:44 UTC
Created attachment 178755 [details] [review]
Convert GErrors to GObject.GError exceptions, and throw them upon returning from calling the C function.

This changes gi to make use of pyglib_error_check() which already exists in pyglib.

The included tests make use of the other patch attached to this bug, to check that the right exception is thrown from the new function in GIMarshallingTests.
two Gtk C functions.