[Libosinfo] [libosinfo] Don't fail when there's an error loading the user DB

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Tue Mar 19 14:04:19 UTC 2013


On Tue, Mar 19, 2013 at 12:49 PM, Daniel P. Berrange
<berrange at redhat.com> wrote:
> On Tue, Mar 19, 2013 at 11:29:36AM +0100, Christophe Fergeau wrote:
>> On Tue, Mar 19, 2013 at 10:18:04AM +0000, Daniel P. Berrange wrote:
>> > On Tue, Mar 19, 2013 at 11:05:21AM +0100, Christophe Fergeau wrote:
>> > > osinfo_loader_process_default_path() currently returns an error if
>> > > there was a problem when parsing the user database. This leads
>> > > application to error out when an invalid XML file is dropped in
>> > > ~/.config/libosinfo/db/
>> > > As the stricter behaviour can be achieved using public libosinfo API,
>> > > we can change osinfo_loader_process_default_path() to be less strict
>> > > and more useful to applications.
>> > > ---
>> > >  osinfo/osinfo_loader.c | 6 ++++--
>> > >  1 file changed, 4 insertions(+), 2 deletions(-)
>> > >
>> > > diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
>> > > index 467af3f..bc17a2e 100644
>> > > --- a/osinfo/osinfo_loader.c
>> > > +++ b/osinfo/osinfo_loader.c
>> > > @@ -1892,8 +1892,10 @@ void osinfo_loader_process_default_path(OsinfoLoader *loader, GError **err)
>> > >          goto error;
>> > >
>> > >      osinfo_loader_process_user_path(loader, &error);
>> > > -    if (error)
>> > > -        goto error;
>> > > +    if (error) {
>> > > +        g_warning("Error loading libosinfo user data: %s", error->message);
>> > > +        g_clear_error(&error);
>> > > +    }
>> >
>> > It would be nice if we defined an error code for the "Directory does not exist"
>> > error scenario, so we can skip that gracefully, but still report an fatal error
>> > for parser problems.
>>
>> This still means applications need to be aware that they need to check
>> _process_default_path() error and ignore some errors (which imho is what
>> you want to do most of the time), so this patch makes things better for
>> this use case.
>
> Oh, no, I mean that if you add a specific error code for this case,
> you can make _process_default_path() skip the "not found" error, and
> still treat othe errors as fatal, instead of using an g_warning.

FWIW, I also prefer what Daniel said. For higher level languages (e.g
Vala) to be able to nicely catch specific errors (rather than having
to check the code), we'll need to specify the type in gir annotation
for 'error' parameter.

-- 
Regards,

Zeeshan Ali (Khattak)
FSF member#5124




More information about the Libosinfo mailing list