[libvirt] g_error considered harmful

Christophe Fergeau cfergeau at redhat.com
Tue Jan 17 15:52:19 UTC 2012


On Tue, Jan 17, 2012 at 02:19:47PM +0100, Marc-André Lureau wrote:
> On Tue, Jan 17, 2012 at 2:05 PM, Christophe Fergeau <cfergeau at redhat.com> wrote:
> > And I forgot to mention that the only remaining use of g_error are in
> > gvir_init_object and gvir_init_config where it's probably acceptable to die
> > if things didn't work as expected.
> 
> Not really, it would be better to return an error.

Looking at what gtk+ does, it has gtk_init which is documented to abort,
and gtk_init_check which apps can use when they need this. g_type_init has
no _check alternative, but it does a few sanity checks at runtime using
g_assert.

I like the gtk+ approach of aborting in the function most commonly use as
it avoids tracking down bugs caused by the _init failing but not being
checked by the application developer. I think we should do the same and add
_check functions if/when needed (this is me being lazy)

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120117/df38202c/attachment-0001.sig>


More information about the libvir-list mailing list