[augeas-devel] Error reporting API

Daniel P. Berrange berrange at redhat.com
Tue Sep 22 09:15:58 UTC 2009


On Mon, Sep 21, 2009 at 05:48:57PM -0700, David Lutterkort wrote:
> 
> This change has been long overdue: API functions to inquire about errors
> and details about them. The function aug_error can be used to get an error
> code for whatever error made the last aug_* fail.
> 
> This functionality is now used by augtool to print error messages, for
> example,
> 
>     augtool> print "/*[1 = 'foo']"
>     error: Invalid path expression
>     error: type error
>     error: /*[1 = 'foo']
> 
> That's a lot friendlier than typing 'print /augeas//error' all the
> time. The main advantage though is that Augeas is easier to use as a
> library now, since you can use the result of aug_error to see if a call
> failed because of an invalid path expression (probably a bug in your
> program) or because of a failed malloc.
> 
> There's still a lot to be done to make error reporting perfect, but this is
> a decent start.
> 
> Note that some calls will always return success even if some aspect of them
> failed. For example, aug_load will tell you it succeeded even if some files
> could not be loaded - that's necessary both for API compatibility, and
> makes good sense. For analyzing the result of aug_load, you still have to
> look at /augeas/files//error.
> 
> One thing I am debating with myself is if the API should implicitly do an
> 'rm /augeas//error' for every call. IOW, error nodes would only stick
> around up until the next call to a aug_* function. The current behavior
> (they stick around until the user removes them) seems to make the API
> harder to use than it has to be.

I think each API call should reset the error code, otherwise the scenario
you describe avove where aug_load returns success but also sets an error
wouldn't be easily handled. If the caller app sees success but finds an
error set, it can't be sure if that error was from from aug_load or a
previous call unless the app itself is careful to always reset the error
before each call. At which point you might as well always reset it 
internally to augeas.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the augeas-devel mailing list