[augeas-devel] How to get better error information?

David Lutterkort lutter at watzmann.net
Mon May 8 22:08:34 UTC 2017


Hi Štěpán,

first off, recent versions of augtool have a 'errors' command that presents
error information in a more readable format.

But in general, I am not sure how to get to a better error message here.
What augeas does in your first example is trying to match the regular
expressions corresponding to 'begin . contents . end' to the input,
literally by creating one big regular expression and then matching it to
the input. The only information it gets back from the matcher
<http://www.delorie.com/gnu/docs/regex/regex_47.html> is 'this didn't
match' without more information how far the matcher got in trying to match.

It might be possible to do some more analysis in this case, e.g. if there
was an error for the whole regex, try to match 'begin', if that works, try
to match 'contents' etc. That strategy will not always be successful though
depending on how a lens is put together.

One strategy that might help is to do these matches from tests, i.e. rather
than use augtool write a test like 'test Minimal.lns get "..." = ?' because
that can then easily be changed to 'test Minimal.contents get "..." = ?'
without having to change the lens. You can then also build up tests that
make sure that the individual parts of lenses you write behave as expected.

I'd love to hear other ideas on how to improve those errors - I know it's
frustrating to be told that something didn't match at all without more
information on why not, but I don't have good ideas on how to address that.


On Thu, May 4, 2017 at 8:50 AM, Štěpán Balážik <stepan.balazik at nic.cz>
wrote:

> Hi,
>
> suppose I have a lens:
>
>     module Minimal =
>       autoload xfm
>
>     let del_str = Util.del_str
>     let eol = Util.eol
>
>     let entry = [label "entry" . store /[0-9]+/] . eol
>
>     let begin = del_str "BEGIN" . eol
>     let contents = entry*
>     let end = del_str "END" . eol
>
>     let lns = begin . contents . end
>
>     let xfm = transform lns (incl "/tmp/minimal")
>
> and file /tmp/minimal:
>
>     BEGIN
>     12
>     32
>     aa
>     45
>     END
>
> This produces a not very informative error message:
>
>     augtool> print /augeas/files/tmp/minimal/error
>     /augeas/files/tmp/minimal/error = "parse_failed"
>     /augeas/files/tmp/minimal/error/pos = "0"
>     /augeas/files/tmp/minimal/error/line = "1"
>     /augeas/files/tmp/minimal/error/char = "0"
>     /augeas/files/tmp/minimal/error/lens = "/usr/share/augeas/lenses/
> dist/minimal.aug:13.10-.32:"
>     /augeas/files/tmp/minimal/error/message = "Input string does not
> match at all"
>
>
> ------------------------------
> Now if I omit the begin and end from both the lens the file so I end up
> with a lens:
>
>     ...
>     let lns = contents
>     ...
>
> and file:
>
>     12
>     32
>     aa
>     45
>
> I get much better and more informative error message:
>
>     augtool> print /augeas/files/tmp/minimal/error
>     /augeas/files/tmp/minimal/error = "parse_failed"
>     /augeas/files/tmp/minimal/error/pos = "5"
>     /augeas/files/tmp/minimal/error/line = "2"
>     /augeas/files/tmp/minimal/error/char = "2"
>     /augeas/files/tmp/minimal/error/lens = "/usr/share/augeas/lenses/
> dist/minimal.aug:10.15-.21:"
>     /augeas/files/tmp/minimal/error/lens/last_matched =
> "/usr/share/augeas/lenses/dist/minimal.aug:7.12-.26:"
>     /augeas/files/tmp/minimal/error/message = "Iterated lens matched less
> than it should"
>
> Is there a way to get the information of the second error message without
> manually omiting the encapsulation of the iterated lens?
>
> Thanks,
> Štěpán
>
> _______________________________________________
> augeas-devel mailing list
> augeas-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/augeas-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20170508/8c668acd/attachment.htm>


More information about the augeas-devel mailing list