augeas icon indicating copy to clipboard operation
augeas copied to clipboard

Shouldn't aug_save() set error variables when failing?

Open hillu opened this issue 7 years ago • 1 comments

While debugging an issue that turned out to be related to https://github.com/dominikh/go-augeas/issues/13, I noticed that aug_save() behaves differently from other functions in that it does not set the fields in aug->error.

augtool tells me to use the errors command to retrieve the errors if save fails. IMO there should be a corresponding error code for API use.

hillu avatar May 11 '17 17:05 hillu

The reason aug_save behaves differently here is that it might encounter many errors - if multiple files have changes, and more than one fails to save, we'd simply run out of place in aug->error to report on that.

If you need details on errors during aug_save, you should match on /augeas/files//error (note the double slash) For a human-readable error, the most important bits of information are probably

  1. the filename: everything in the path that aug_match returns between /augeas/files and /error.
  2. human-readable message: error/message
  3. kind/internal error code: the value of the error node

Note that aug_load reports errors on reading files with the same mechanism. If you want to avoid getting fooled by these errors when analyzing the result of aug_save, you need to rm /augeas/files//error before calling aug_save.

lutter avatar Sep 29 '17 04:09 lutter