[augeas-devel] Better error message when iteration fails during put

David Lutterkort lutter at redhat.com
Fri Mar 5 01:40:30 UTC 2010


Brandon Whalen's experience with the impenetrable 'Short iteration'
error inspired me to try and improve the error message a little. In his
case, he'd get with the patch below a message

        Malformed child node 'KeepAlive'
        
rather than "Short iteration".

David

>From 420fca95fb760fbe9f33c2034f5103a54f5970e1 Mon Sep 17 00:00:00 2001
From: David Lutterkort <lutter at redhat.com>
Date: Thu, 4 Mar 2010 17:30:33 -0800
Subject: [PATCH 1/2] Produce a better error when iteration stops prematurely during put/create

We now try to include the name of the child node that caused us to stop in
the error message.
---
 src/put.c |   38 +++++++++++++++++++++++++++++++-------
 1 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/put.c b/src/put.c
index e4024b8..571e626 100644
--- a/src/put.c
+++ b/src/put.c
@@ -82,7 +82,7 @@ static void put_error(struct state *state, struct lens *lens,
     state->error->lens = ref(lens);
     state->error->pos  = -1;
     if (strlen(state->path) == 0) {
-        state->error->path = strdup("(root)");
+        state->error->path = strdup("");
     } else {
         state->error->path = strdup(state->path);
     }
@@ -505,28 +505,50 @@ static void put_concat(struct lens *lens, struct state *state) {
     state->skel = oldskel;
 }
 
+static void error_quant_star(struct split *last_split, struct lens *lens,
+                             struct state *state) {
+    struct tree *child = NULL;
+    if (last_split != NULL) {
+        if (last_split->follow != NULL) {
+            child = last_split->follow;
+        } else {
+            for (child = last_split->tree;
+                 child != NULL && child->next != NULL;
+                 child = child->next);
+        }
+    }
+    if (child == NULL) {
+        put_error(state, lens, "Malformed child node");
+    } else {
+        put_error(state, lens, "Malformed child node '%s'", child->label);
+    }
+}
+
 static void put_quant_star(struct lens *lens, struct state *state) {
     assert(lens->tag == L_STAR);
     struct split *oldsplit = state->split;
     struct skel *oldskel = state->skel;
+    struct split *last_split = NULL;
 
     struct split *split = split_iter(state, lens);
 
     state->skel = state->skel->skels;
     set_split(state, split);
+    last_split = state->split;
     while (state->split != NULL && state->skel != NULL) {
         put_lens(lens->child, state);
         state->skel = state->skel->next;
+        last_split = state->split;
         next_split(state);
     }
     while (state->split != NULL) {
         create_lens(lens->child, state);
+        last_split = state->split;
         next_split(state);
     }
+    if (state->pos != oldsplit->end)
+        error_quant_star(last_split, lens, state);
     list_free(split);
-    if (state->pos != oldsplit->end) {
-        put_error(state, lens, "Short iteration");
-    }
     set_split(state, oldsplit);
     state->skel = oldskel;
 }
@@ -657,18 +679,20 @@ static void create_concat(struct lens *lens, struct state *state) {
 static void create_quant_star(struct lens *lens, struct state *state) {
     assert(lens->tag == L_STAR);
     struct split *oldsplit = state->split;
+    struct split *last_split = NULL;
 
     struct split *split = split_iter(state, lens);
 
     set_split(state, split);
+    last_split = state->split;
     while (state->split != NULL) {
         create_lens(lens->child, state);
+        last_split = state->split;
         next_split(state);
     }
+    if (state->pos != oldsplit->end)
+        error_quant_star(last_split, lens, state);
     list_free(split);
-    if (state->pos != oldsplit->end) {
-        put_error(state, lens, "Short iteration");
-    }
     set_split(state, oldsplit);
 }
 
-- 
1.6.6.1






More information about the augeas-devel mailing list