range: Change error handling of elektraRangeGet():
1. Validate all keys, but always return ELETRA_PLUGIN_STATUS_SUCCESS regardless of validation problems.
2. Treat all errors as warnings.
@@ -420,7 +420,7 @@ static RangeType getType (const Key * key)
return type;
}
-static int validateKey (Key * key, Key * parentKey)
+static int validateKey (Key * key, Key * parentKey, bool errorsAsWarnings)
{
const Key * rangeMeta = keyGetMeta (key, "check/range");
const char * rangeString = keyString (rangeMeta);
@@ -447,15 +447,30 @@ static int validateKey (Key * key, Key * parentKey)
int rc = validateSingleRange (keyString (key), rangeString, type);
if (rc == -1)
{
+ if(errorsAsWarnings) {
+ ELEKTRA_ADD_VALIDATION_SYNTACTIC_WARNINGF (parentKey, "Invalid syntax: %s", keyString (rangeMeta));
+ return 1;
+ }
+ else {
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Invalid syntax: %s", keyString (rangeMeta));
return -1;
}
+ }
else if (rc == 0)
+ {
+ if (errorsAsWarnings)
+ {
+ ELEKTRA_ADD_VALIDATION_SEMANTIC_WARNINGF(parentKey, RANGE_ERROR_MESSAGE, keyString (key), keyName (key),
+ rangeString);
+ return 0;
+ }
+ else
{
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (parentKey, RANGE_ERROR_MESSAGE, keyString (key), keyName (key),
rangeString);
return 0;
}
+ }
else
{
return rc;
@@ -466,9 +481,15 @@ static int validateKey (Key * key, Key * parentKey)
int rc = validateMultipleRanges (keyString (key), rangeString, parentKey, type);
if (rc == 0)
{
+ if(errorsAsWarnings) {
+ ELEKTRA_ADD_VALIDATION_SEMANTIC_WARNINGF (parentKey, RANGE_ERROR_MESSAGE, keyString (key), keyName (key),
+ rangeString);
+ }
+ else {
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (parentKey, RANGE_ERROR_MESSAGE, keyString (key), keyName (key),
rangeString);
}
+ }
return rc;
}
}
@@ -490,9 +511,20 @@ int elektraRangeGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_U
return 1; // success
}
- // get all keys
- return 1; // success
+ // Validate all keys, treat errors as warnings.
+ Key * cur;
+ while ((cur = ksNext (returned)) != NULL)
+ {
+ const Key * meta = keyGetMeta (cur, "check/range");
+ if (meta)
+ {
+ validateKey (cur, parentKey, true);
+ }
+ }
+
+ // Always return 1. We don't want kdbGet() to fail, because of validation problems.
+ return ELEKTRA_PLUGIN_STATUS_SUCCESS; // success
}
int elektraRangeSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
@@ -505,7 +537,7 @@ int elektraRangeSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_U
const Key * meta = keyGetMeta (cur, "check/range");
if (meta)
{
- int rc = validateKey (cur, parentKey);
+ int rc = validateKey (cur, parentKey, false);
if (rc <= 0)
{
return -1;
