changeset 205:c42a9c3f4d55

Improve error handling in th_config.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 11 Feb 2016 23:41:26 +0200
parents 55f429dff750
children c2193323736d
files th_config.c
diffstat 1 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/th_config.c	Thu Feb 11 23:14:54 2016 +0200
+++ b/th_config.c	Thu Feb 11 23:41:26 2016 +0200
@@ -236,7 +236,7 @@
             case EOF:
                 if (parseMode != PM_IDLE)
                 {
-                    th_io_error(ctx, -1, "Unexpected end of file.\n");
+                    th_io_error(ctx, THERR_OUT_OF_DATA, "Unexpected end of file.\n");
                     parseMode = PM_ERROR;
                 }
                 else
@@ -280,7 +280,7 @@
                     goto out;
                 else
                 {
-                    th_io_error(ctx, -1,
+                    th_io_error(ctx, THERR_INVALID_DATA,
                         "Invalid nesting sequence encountered.\n");
                     parseMode = PM_ERROR;
                 }
@@ -295,7 +295,8 @@
             else
             {
                 // Error! Invalid character found
-                th_io_error(ctx, -1, "Unexpected character '%c'.\n", c);
+                th_io_error(ctx, THERR_INVALID_DATA,
+                    "Unexpected character '%c'.\n", c);
                 parseMode = PM_ERROR;
             }
             break;
@@ -323,7 +324,7 @@
                 else
                 {
                     // Error! Key name string too long!
-                    th_io_error(ctx, -1, "Config key name too long!");
+                    th_io_error(ctx, THERR_INVALID_DATA, "Config key name too long!");
                     parseMode = PM_ERROR;
                 }
                 c = -1;
@@ -332,7 +333,7 @@
             {
                 // Error! Invalid character found
                 tmpStr[strPos] = 0;
-                th_io_error(ctx, -1,
+                th_io_error(ctx, THERR_INVALID_DATA,
                     "Unexpected character '%c' in key name '%s'.\n",
                     c, tmpStr);
                 parseMode = PM_ERROR;
@@ -393,7 +394,7 @@
                 else
                 {
                     // Error! No configuration key by this name found
-                    th_io_error(ctx, -1,
+                    th_io_error(ctx, THERR_INVALID_DATA,
                         "No such configuration setting ('%s')\n",
                         tmpStr);
                     parseMode = PM_ERROR;
@@ -404,7 +405,7 @@
             else
             {
                 // Error! '=' expected!
-                th_io_error(ctx, -1,
+                th_io_error(ctx, THERR_INVALID_DATA,
                     "Unexpected character '%c', assignation '=' was expected.\n",
                     c);
                 parseMode = PM_ERROR;
@@ -468,7 +469,7 @@
             if (c != '{')
             {
                 // Error! Section start '{' expected!
-                th_io_error(ctx, -1,
+                th_io_error(ctx, THERR_INVALID_DATA,
                     "Unexpected character '%c', section start '{' was expected.\n",
                     c);
                 parseMode = PM_ERROR;
@@ -531,7 +532,7 @@
                 else
                 {
                     // Error! String too long!
-                    th_io_error(ctx, -1,
+                    th_io_error(ctx, THERR_INVALID_DATA,
                         "String too long! Maximum is %d characters.",
                         SET_MAX_BUF);
                     parseMode = PM_ERROR;
@@ -546,7 +547,7 @@
             if (isStart && item->type == ITEM_UINT && c == '-')
             {
                 // Error! Negative values not allowed for unsigned ints
-                th_io_error(ctx, -1,
+                th_io_error(ctx, THERR_INVALID_DATA,
                     "Negative value specified for %s, unsigned value expected.",
                     item->name);
                 parseMode = PM_ERROR;
@@ -606,7 +607,7 @@
             else
             {
                 // Error! Unexpected character.
-                th_io_error(ctx, -1,
+                th_io_error(ctx, THERR_INVALID_DATA,
                     "Unexpected character '%c' for numeric setting '%s'.",
                     c, item->name);
                 parseMode = PM_ERROR;
@@ -615,7 +616,7 @@
             if (isError)
             {
                 // Error! String too long!
-                th_io_error(ctx, -1,
+                th_io_error(ctx, THERR_INVALID_DATA,
                     "String too long! Maximum is %d characters.",
                     SET_MAX_BUF);
                 parseMode = PM_ERROR;
@@ -655,7 +656,7 @@
 
             if (isError)
             {
-                th_io_error(ctx, -1,
+                th_io_error(ctx, THERR_INVALID_DATA,
                     "Invalid boolean value for '%s'.\n",
                     item->name);
                 parseMode = PM_ERROR;