better error handling
authorPhilipp Takacs <philipp@bureaucracy.de>
Mon, 25 Apr 2016 14:19:54 +0000 (16:19 +0200)
committerPhilipp Takacs <philipp@bureaucracy.de>
Sun, 1 May 2016 17:56:31 +0000 (19:56 +0200)
only warn for LENERR2, or ignore it in some cases

sbr/readconfig.c
uip/mhparse.c
uip/new.c
uip/pick.c
uip/prompter.c
uip/slocal.c
uip/sortm.c
uip/whom.c

index 6975d72..45e1cb6 100644 (file)
@@ -48,6 +48,9 @@ readconfig(struct node **npp, FILE *ib, char *file, int ctx)
 
        for (state = FLD2;;) {
                switch (state = m_getfld2(state, &f, ib)) {
+               case LENERR2:
+                       state = FLD2;
+                       /* FALL */
                case FLD2:
                        np = mh_xcalloc(1, sizeof(*np));
                        *npp = np;
@@ -68,7 +71,10 @@ readconfig(struct node **npp, FILE *ib, char *file, int ctx)
                                }
                        }
                        continue;
-
+               case FMTERR2:
+                       advise(NULL, "%s is poorly formated", file);
+                       state = FLD2;
+                       continue;
                case BODY2:
                        adios(EX_CONFIG, NULL, "no blank lines are permitted in %s",
                                        file);
@@ -76,6 +82,10 @@ readconfig(struct node **npp, FILE *ib, char *file, int ctx)
                case FILEEOF2:
                        break;
 
+               case IOERR2:
+                       adios(EX_IOERR, NULL, "m_getfld2", "some error happend");
+                       break;
+
                default:
                        adios(EX_CONFIG, NULL, "%s is poorly formatted", file);
                }
index 67d769c..c250675 100644 (file)
@@ -250,6 +250,10 @@ get_content(FILE *in, char *file, int toplevel)
        */
        for (compnum = 1, state = FLD2;;) {
                switch (state = m_getfld2(state, &f, in)) {
+               case LENERR2:
+                       advise(NULL, "To long field");
+                       state = FLD2;
+                       /* FALL */
                case FLD2:
                        compnum++;
 
@@ -267,11 +271,13 @@ get_content(FILE *in, char *file, int toplevel)
                        ct->c_begin = ftell(in);
                        break;
 
-               case LENERR2:
                case FMTERR2:
+                       advise(NULL, "message format error in component #%d", compnum);
+                       state = FLD2;
+                       continue;
+
                case IOERR2:
-                       adios(EX_DATAERR, NULL, "message format error in component #%d",
-                                       compnum);
+                       adios(EX_IOERR, "m_getfld2", "io error");
 
                default:
                        adios(EX_SOFTWARE, NULL, "getfld() returned %d", state);
index 4335892..efbea04 100644 (file)
--- a/uip/new.c
+++ b/uip/new.c
@@ -108,6 +108,10 @@ get_msgnums(char *folder, char *sequences[])
 
        for (state = FLD2;;) {
                switch (state = m_getfld2(state, &f, fp)) {
+               case LENERR2:
+                       state = FLD2;
+                       /* FALL */
+
                case FLD2:
                        /*
                        ** if it's in a sequence we want,
index 5df2861..b0205fd 100644 (file)
@@ -1261,8 +1261,12 @@ plist
 
                case LENERR2:
                case FMTERR2:
-               case IOERR2:
                        advise(NULL, "format error in message %d", msgnum);
+                       state = FLD2;
+                       continue;
+
+               case IOERR2:
+                       adios(EX_IOERR, "m_getfld2", "io error on message %d", msgnum);
                        /* FALL */
 
                case BODY2:
index c7eb957..bc7cd43 100644 (file)
@@ -140,6 +140,10 @@ main(int argc, char **argv)
        */
        for (state = FLD2;;) {
                switch (state = m_getfld2(state, &f, in)) {
+               case LENERR2:
+                       advise(NULL, "Header to long");
+                       state = FLD2;
+                       /* FALL */
                case FLD2:
                        /*
                        ** Check if the value of field contains
@@ -212,6 +216,9 @@ abort:
                                        }
                                } while ((state = m_getfld2(state, &f, in))
                                                ==BODY2);
+                               if (state != FILEEOF2) {
+                                       adios(EX_IOERR, "m_getfld2", "io error");
+                               }
                        }
 
                        if (prepend || !qbody) {
@@ -230,8 +237,11 @@ has_no_body:
                        }
                        break;
 
+               case FMTERR2:
+                       advise(NULL, "skeleton is poorly formatted");
+                       continue;
                default:
-                       adios(EX_DATAERR, NULL, "skeleton is poorly formatted");
+                       adios(EX_IOERR, "m_getfld2", "io error");
                }
                break;
        }
index f8f9d95..26cad52 100644 (file)
@@ -758,6 +758,11 @@ parse(int fd)
        */
        for (i = 0, state = FLD2;;) {
                switch (state = m_getfld2(state, &f, in)) {
+               case LENERR2:
+                       advise(NULL, "format error in message");
+                       state = FLD2;
+                       /* FALL */
+
                case FLD2:
                        lp = mh_xstrdup(f.value);
                        for (p = hdrs; p->p_name; p++) {
@@ -793,7 +798,6 @@ parse(int fd)
                case FILEEOF2:
                        break;
 
-               case LENERR2:
                case FMTERR2:
                case IOERR2:
                        advise(NULL, "format error in message");
index 56fa7cb..061ae5a 100644 (file)
@@ -331,6 +331,10 @@ get_fields(char *datesw, int msg, struct smsg *smsg)
        }
        for (compnum = 1, state = FLD2;; compnum++) {
                switch (state = m_getfld2(state, &f, in)) {
+               case LENERR2:
+                       admonish(NULL, "To long header field in message %d (header %s, #%d)", msg, f.name, compnum);
+                       state = FLD2;
+                       /* FALL */
                case FLD2:
                        if (mh_strcasecmp(f.name, datesw)==0) {
                                datecomp = mh_xstrdup(f.value);
@@ -350,7 +354,6 @@ get_fields(char *datesw, int msg, struct smsg *smsg)
                case FILEEOF2:
                        break;
 
-               case LENERR2:
                case FMTERR2:
                case IOERR2:
                        admonish(NULL, "format error in message %d (header #%d)", msg, compnum);
index daca343..e02994f 100644 (file)
@@ -215,6 +215,10 @@ process(char *file)
 
        for (compnum=1, state=FLD2;; compnum++) {
                switch (state = m_getfld2(state, &f, in)) {
+               case LENERR2:
+                       advise(NULL, "field %d contains a to long line", f.name);
+                       state = FLD2;
+                       /* FALL */
                case FLD2:
                        proc_hdr(f.name, f.value);
                        continue;
@@ -223,7 +227,6 @@ process(char *file)
                case FILEEOF2:
                        break;
 
-               case LENERR2:
                case FMTERR2:
                case IOERR2:
                        adios(EX_DATAERR, NULL, "message format error in component #%d",