[augeas-devel] Newbie to augeas: Questions about perl interface

Raphaël Pinson raphink at gmail.com
Fri Feb 3 17:31:48 UTC 2012


Hello Peter,


On Fri, Feb 3, 2012 at 5:45 PM, Peter Valdemar Mørch <peter at morch.com> wrote:
> My questions are mostly about error reporting and $aug->set().
>
> First, Config-Augeas-0.902/lib/Config/Augeas.pm has:
>
> =head2 set ( path, value )
>
> Set the value associated with C<path> to C<value>. C<value> is copied
> into Augeas internal data structure. Intermediate entries are created
> if they don't exist. Return 1 on success, 0 on error. It is an error
> if more than one node matches C<path>.
>
> =cut
>
> sub set {
>    my $self  = shift ;
>    my $path  = shift || croak __PACKAGE__," set: undefined path";
>    my $value = shift ;
>
>    croak __PACKAGE__," set: undefined value" unless defined $value;
>
>    my $result ;
>    my $ret = $self->{aug_c} -> set($path,$value) ;
>
>    return 1 if $ret == 0;
>
>    $self -> print('/augeas') ;
>    croak __PACKAGE__," set: error with path $path";
> }
>
> Hey! sub set {} *never* returns 0. If it doesn't return 1, it prints a
> _large_ data structure to STDOUT and then croaks!!! Is there a good
> reason for this? Is there a way to avoid this library printing to
> STDOUT? As I see it, there is no way to  eval { $avg->set } without
> having STDOUT spammed in case of an error. Our STDOUT is valuable -
> our app simply cannot survive a library printing errors to STDOUT. At
> the very least, there is a mismatch between implementation and
> documentation, right?

I inherited Config::Augeas recently from Dominique Dumont, who
originally developed it for his Config::Model package.
This is a part I haven't yet modified, but I see what you mean.

Would it be easier for you if this function actually returned 0 and
let you do an $aug->get("/augeas//error") yourself to find the
problem?


> Second, I was hoping $aug->set() could be used to add a line to
> /etc/fstab like this:
>
> $aug->set('/files/etc/fstab/01', {
>    spec => '/dev',
>    file => '/foo',
>    vfstype => 'none',
>    opt => [ 'rw', 'bind' ],
>    dump => 0,
>    passno => 0
> }) or die;
>
> It can't. Is any reason for that? It should be an easy patch, no?
> (I'll propose one if there are no objections)


Just like the aug_set C function, $aug->set() takes a single value as
argument, so you need to pass the values one by one.
That said, you're welcome to propose a patch to pass a hashref if
that's useful to you (that would make it closer to the behavior of the
Augeas puppet module, using context and changes).


> Third, the above set() fails (the subsequent save fails), but it
> returns 1 (since it doesn't die) and doesn't set an error:
> printf "set error? %s : %s\n", $aug->error(), $aug->error_message();
> prints
> save error: noerror : No error

$aug->error() and $aug->error_message() only return the API error
codes and messages (as returned by the C library). The actual set
error can be found by running $aug->get("/augeas//error") as Augeas
keeps all its errors in the /augeas tree.


> A subsequent save:
> if (! $aug->save() ) {
>    printf "save error: %s : %s\n", $aug->error(), $aug->error_message();
> }
> prints
> save error: noerror : No error
>
> This time, save returns 0, but there is no error information. Long
> term, (e.g. if there are many set()-s), this doesn't make it easy to
> track down where things went wrong... Isn't it reasonable to expect
> that the set() that causes save to fail should fail, or that save()
> should give some info about why it didn't return 1?
>
> Am I missing something?
>
> Fourth, is there a repository for perl-augeas ?
> https://fedorahosted.org/web/ has java-augeas, ruby-augeas and
> python-augeas only.


Yes, it's currently kept on github: https://github.com/raphink/config-augeas
You're welcome to propose merges.


Cheers,


Raphaël




More information about the augeas-devel mailing list