GNOME Bugzilla – Bug 639834
GI does not make use of GObject.GError; instead RuntimeError is thrown whenever a GError is returned from a C function.
Last modified: 2011-01-19 17:27:47 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.
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.
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.
Created attachment 178748 [details] [review] Add GIMarshallingTests function which sets a GError, to test exception handling in bindings.
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.
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.
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.
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.