# HG changeset patch # User Matti Hamalainen # Date 1455226886 -7200 # Node ID c42a9c3f4d5534edcb8907c7049e5abe6fbf2752 # Parent 55f429dff750e11a6aa6f98244fdc45254b623ad Improve error handling in th_config. diff -r 55f429dff750 -r c42a9c3f4d55 th_config.c --- 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;