On Thu, May 13, 2010 at 02:34:03PM +0100, Matthew Booth wrote:
Add a function to display more complete augeas errors if they occur.
Update all
uses of augeas in GuestOS::RedHat to use it for error reporting.
ACK, but:
+sub _augeas_error
+{
+ my $self = shift;
+ my ($err) = @_; # The original error message. We will emit this if there
+ # were no augeas errors.
+
+ my $g = $self->{g};
+
+ my $msg = "";
+
+ foreach my $error ($g->aug_match('/augeas/files//error')) {
+ $error =~ /^\/augeas\/files(\/.*)\/error$/
+ or die("Unexpected return from aug_match: $error");
+ my $file = $1;
+
+ my %detail;
+ foreach my $detail_path ($g->aug_match("$error//*")) {
+ $detail_path =~ /^$error\/(.*)$/
+ or die("Unexpected return from aug_match: $detail_path");
+ $detail{$1} = $g->aug_get($detail_path);
+ }
+
+ if (defined($detail{message})) {
+ $msg .= __x("augeas error for {file}: {error}",
+ file => $file,
+ error => $detail{message})."\n";
+ } else {
+ $msg .= __x("augeas error for {file}",
+ file => $file)."\n";
+ }
+
+ if (defined($detail{pos}) && defined($detail{line}) &&
+ defined($detail{char}))
+ {
+ $msg .= __x("error at line {line}, char {char}, file ".
+ "position {pos}",
+ line => $detail{line},
+ char => $detail{char},
+ pos => $detail{pos})."\n";
+ }
+
+ if (defined($detail{lens})) {
+ $msg .= __x("augeas lens: {lens}",
+ lens => $detail{lens})."\n";
+ }
+ }
+
+ chomp($msg);
+
+ die(user_message($msg)) if (length($msg) > 0);
+ die($err);
+}
If the Augeas functions in this function fail, then you might end up
losing information. How about wrapping most of this function in a big
eval?
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming blog:
http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora