Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
error: recategorized errors, removed some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZronekM committed Jun 22, 2019
1 parent a701c22 commit 487b8ac
Show file tree
Hide file tree
Showing 25 changed files with 103 additions and 115 deletions.
4 changes: 2 additions & 2 deletions src/libs/elektra/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Plugin * elektraPluginOpen (const char * name, KeySet * modules, KeySet * config
{
if ((handle->kdbOpen (handle, errorKey)) == -1)
{
ELEKTRA_ADD_INSTALLATION_WARNINGF (
ELEKTRA_ADD_BROKEN_PLUGIN_WARNINGF (
errorKey,
"Open of plugin returned unsuccessfully: %s. Reason contains plugin, see other warnings for details", name);
elektraPluginClose (handle, errorKey);
Expand Down Expand Up @@ -328,7 +328,7 @@ int elektraPluginClose (Plugin * handle, Key * errorKey)
if (handle->kdbClose)
{
rc = handle->kdbClose (handle, errorKey);
if (rc == -1) ELEKTRA_ADD_INSTALLATION_WARNING (errorKey, "kdbClose() failed");
if (rc == -1) ELEKTRA_ADD_GENERAL_RESOURCE_WARNING (errorKey, "kdbClose() failed");
}

ksDel (handle->config);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/augeas/augeas.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ int elektraAugeasOpen (Plugin * handle, Key * parentKey)

if (ret >= 0)
{
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (parentKey, "Unable to allocate memory for a detailed augeas error message");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Unable to allocate memory for a detailed augeas error message");
return -1;
}

Expand Down Expand Up @@ -519,7 +519,7 @@ int elektraAugeasGet (Plugin * handle, KeySet * returned, Key * parentKey)
if (!conversionData)
{
fclose (fh);
ELEKTRA_SET_INSTALLATION_ERRORF (
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (
parentKey, "Unknown or unsupported type found during streaming, assume key as string, type lost. Errno: %s",
strerror (errno));
}
Expand Down
24 changes: 12 additions & 12 deletions src/plugins/conditionals/conditionals.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static CondResult evalCondition (const Key * curKey, const char * leftSide, Comp
}
if (elektraRealloc ((void **) &compareTo, endPos - rightSide) < 0)
{
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (parentKey, "Out of memory");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Out of memory");
result = ERROR;
goto Cleanup;
}
Expand All @@ -228,7 +228,7 @@ static CondResult evalCondition (const Key * curKey, const char * leftSide, Comp

if (elektraRealloc ((void **) &lookupName, len) < 0)
{
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (parentKey, "Out of memory");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Out of memory");
result = ERROR;
goto Cleanup;
}
Expand All @@ -253,7 +253,7 @@ static CondResult evalCondition (const Key * curKey, const char * leftSide, Comp
}
if (elektraRealloc ((void **) &compareTo, keyGetValueSize (key)) < 0)
{
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (parentKey, "Out of memory");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Out of memory");
result = ERROR;
goto Cleanup;
}
Expand All @@ -269,7 +269,7 @@ static CondResult evalCondition (const Key * curKey, const char * leftSide, Comp

if (elektraRealloc ((void **) &lookupName, len) < 0)
{
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (parentKey, "Out of memory");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Out of memory");
result = ERROR;
goto Cleanup;
}
Expand Down Expand Up @@ -564,8 +564,8 @@ static CondResult parseCondition (Key * key, const char * condition, const Key *

if ((regcomp (&regex, regexString, REG_EXTENDED | REG_NEWLINE)))
{
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (parentKey,
"Couldn't compile regex: most likely out of memory"); // the regex compiles so the only
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey,
"Couldn't compile regex: most likely out of memory"); // the regex compiles so the only
// possible error would be out of
// memory
ksDel (ks);
Expand Down Expand Up @@ -619,17 +619,17 @@ static CondResult parseConditionString (const Key * meta, const Key * suffixList
CondResult ret;
if ((ret = regcomp (&regex1, regexString1, REGEX_FLAGS_CONDITION)))
{
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (parentKey,
"Couldn't compile regex: most likely out of memory"); // the regex compiles so the only
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey,
"Couldn't compile regex: most likely out of memory"); // the regex compiles so the only
// possible error would be out of
// memory
ksDel (ks);
return ERROR;
}
if ((ret = regcomp (&regex2, regexString2, REGEX_FLAGS_CONDITION)))
{
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (parentKey,
"Couldn't compile regex: most likely out of memory"); // the regex compiles so the only
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey,
"Couldn't compile regex: most likely out of memory"); // the regex compiles so the only
// possible error would be out of
// memory
regfree (&regex1);
Expand All @@ -638,8 +638,8 @@ static CondResult parseConditionString (const Key * meta, const Key * suffixList
}
if ((ret = regcomp (&regex3, regexString3, REGEX_FLAGS_CONDITION)))
{
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (parentKey,
"Couldn't compile regex: most likely out of memory"); // the regex compiles so the only
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey,
"Couldn't compile regex: most likely out of memory"); // the regex compiles so the only
// possible error would be out of
// memory
regfree (&regex1);
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/crypto/openssl_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,16 @@ int elektraCryptoOpenSSLHandleCreate (elektraCryptoHandle ** handle, KeySet * co
{
keyDel (key);
keyDel (iv);
ELEKTRA_SET_ASSERTION_ERROR (errorKey, "Failed to create handle! Invalid key length.");
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "Failed to create handle! Invalid key length.");
return -1;
}

if (keyGetValueSize (iv) != ELEKTRA_CRYPTO_SSL_BLOCKSIZE)
{
keyDel (key);
keyDel (iv);
// TODO: Correct?
ELEKTRA_SET_ASSERTION_ERROR (errorKey, "Failed to create handle! Invalid IV length.");

ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "Failed to create handle! Invalid IV length.");
return -1;
}

Expand Down
3 changes: 1 addition & 2 deletions src/plugins/curlget/curlget.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,6 @@ int elektraCurlgetSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA
++(data->setPhase);
if (strncmp ((char *) data->lastHash, (char *) hash, MD5_DIGEST_LENGTH))
{
// TODO: Correct?
ELEKTRA_SET_CONFLICTING_STATE_ERROR (parentKey, "remote file has changed");
retval = -1;
}
Expand All @@ -734,7 +733,7 @@ int elektraCurlgetSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA
else
{
close (fd);
ELEKTRA_SET_GENERAL_RESOURCE_ERRORF (
ELEKTRA_SET_CONFLICTING_STATE_ERRORF (
parentKey, "Failed to fetch configuration from %s. Aborting because consistency can't be ensured",
data->getUrl);
if (data->tmpFile) unlink (data->tmpFile);
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/dump/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ int unserialise (std::istream & is, ckdb::Key * errorKey, ckdb::KeySet * ks)
ss >> version;
if (version != "1")
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (errorKey, "Wrong version detected in dumpfile: %s",
version.c_str ());
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Wrong version detected in dumpfile: %s", version.c_str ());
return -1;
}
}
Expand Down Expand Up @@ -189,7 +188,7 @@ int unserialise (std::istream & is, ckdb::Key * errorKey, ckdb::KeySet * ks)
}
else
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (errorKey, "Wrong version detected in dumpfile: %s", command.c_str ());
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Wrong version detected in dumpfile: %s", command.c_str ());
return -1;
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/gitresolver/gitresolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ int elektraGitresolverGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELE
int rc = pullFromRemote (data, repo);
if (rc)
{
// TODO: Correct?
ELEKTRA_SET_CONFLICTING_STATE_ERROR (parentKey, "Fast-forward pull failed, please pull manually\n");
git_repository_free (repo);
git_libgit2_shutdown ();
Expand Down Expand Up @@ -861,7 +860,6 @@ int elektraGitresolverSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELE
if (newCommit)
{
// newer commit in repo - abort
// TODO: Correct?
ELEKTRA_SET_CONFLICTING_STATE_ERROR (parentKey, "The repository has been updated and is ahead of you");
elektraFree (newCommit);
git_reference_free (headRef);
Expand All @@ -880,7 +878,6 @@ int elektraGitresolverSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELE
char * newObj = hasNewObjectCommit (data, blob);
if (newObj)
{
// TODO: Correct?
ELEKTRA_SET_CONFLICTING_STATE_ERROR (parentKey, "The repository has been updated and is ahead of you");
elektraFree (newObj);
git_object_free (blob);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/gpgme/gpgme.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static gpgme_key_t * extractRecipientFromPluginConfig (KeySet * config, Key * er
err = gpgme_get_key (ctx, keyString (gpgRecipientRoot), &key, 0);
if (err)
{
// TODO: Correct?
// TODO: Correct??
ELEKTRA_SET_ASSERTION_ERRORF (errorKey, "Failed to receive the GPG key because: %s", gpgme_strerror (err));
elektraGpgmeKeylistFree (&list);
return NULL;
Expand Down Expand Up @@ -183,7 +183,7 @@ static gpgme_key_t * extractRecipientFromPluginConfig (KeySet * config, Key * er
err = gpgme_get_key (ctx, keyString (k), &key, 0);
if (err)
{
// TODO: Correct?
// TODO: Correct??
ELEKTRA_SET_ASSERTION_ERRORF (errorKey, "Failed to receive the GPG key because: %s",
gpgme_strerror (err));
elektraGpgmeKeylistFree (&list);
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/hexnumber/hexnumber.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ static int convertHexToDec (Key * key, Key * parentKey)
int result = snprintf (NULL, 0, "%llu", value);
if (result < 0)
{
// TODO: Correct?
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Unable to convert '%s' into decimal", hexValue);
return ELEKTRA_PLUGIN_STATUS_ERROR;
}
Expand All @@ -99,7 +98,6 @@ static int convertHexToDec (Key * key, Key * parentKey)
result = snprintf (decValue, length, "%llu", value);
if (result < 0)
{
// TODO: Correct?
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Unable to convert '%s' into decimal", hexValue);
elektraFree (decValue);
return ELEKTRA_PLUGIN_STATUS_ERROR;
Expand Down Expand Up @@ -154,7 +152,6 @@ static int convertDecToHex (Key * key, Key * parentKey)
const int result = snprintf (NULL, 0, "0x%llx", value);
if (result < 0)
{
// TODO: Correct?
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Unable to convert '%s' into hexadecimal", decValue);
return ELEKTRA_PLUGIN_STATUS_ERROR;
}
Expand All @@ -169,7 +166,6 @@ static int convertDecToHex (Key * key, Key * parentKey)

if (snprintf (hexValue, length, "0x%llx", value) < 0)
{
// TODO: Correct?
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Unable to convert '%s' into hexadecimal", decValue);
elektraFree (hexValue);
return ELEKTRA_PLUGIN_STATUS_ERROR;
Expand Down
21 changes: 9 additions & 12 deletions src/plugins/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ int elektraIconvGet (Plugin * handle, KeySet * returned, Key * parentKey)
memcpy (convertedData, keyString (meta), keyGetValueSize (meta));
if (kdbbUTF8Engine (handle, UTF8_FROM, &convertedData, &convertedDataSize))
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (
parentKey, "Could not convert string %s, got result %s, encoding settings are from %s to %s",
keyString (meta), convertedData, getFrom (handle), getTo (handle));
elektraFree (convertedData);
Expand Down Expand Up @@ -231,11 +230,10 @@ int elektraIconvSet (Plugin * handle, KeySet * returned, Key * parentKey)
memcpy (convertedData, keyString (cur), keyGetValueSize (cur));
if (kdbbUTF8Engine (handle, UTF8_TO, &convertedData, &convertedDataSize))
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (parentKey,
"Could not convert string %s, got result %s,"
" encoding settings are from %s to %s (but swapped for write)",
keyString (cur), convertedData, getFrom (handle), getTo (handle));
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey,
"Could not convert string %s, got result %s,"
" encoding settings are from %s to %s (but swapped for write)",
keyString (cur), convertedData, getFrom (handle), getTo (handle));
elektraFree (convertedData);
return -1;
}
Expand All @@ -252,11 +250,10 @@ int elektraIconvSet (Plugin * handle, KeySet * returned, Key * parentKey)
memcpy (convertedData, keyString (meta), keyGetValueSize (meta));
if (kdbbUTF8Engine (handle, UTF8_TO, &convertedData, &convertedDataSize))
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (parentKey,
"Could not convert string %s, got result %s,"
" encodings settings are from %s to %s (but swapped for write)",
keyString (meta), convertedData, getFrom (handle), getTo (handle));
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey,
"Could not convert string %s, got result %s,"
" encodings settings are from %s to %s (but swapped for write)",
keyString (meta), convertedData, getFrom (handle), getTo (handle));
elektraFree (convertedData);
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/ipaddr/ipaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static int validateKey (Key * key, Key * parentKey)
}
else if (rc == -1)
{
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (parentKey, "Out of memory");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Out of memory");
rc = 0;
}

Expand Down
16 changes: 8 additions & 8 deletions src/plugins/jni/jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,56 +234,56 @@ int elektraJniOpen (Plugin * handle, Key * errorKey)
data->clsPlugin = (*data->env)->FindClass (data->env, classname);
if (data->clsPlugin == 0)
{
ELEKTRA_SET_INTERFACE_ERRORF (errorKey, "Cannot find class %s", classname);
ELEKTRA_SET_GENERAL_RESOURCE_ERRORF (errorKey, "Cannot find class %s", classname);
return -1;
}

data->clsKey = (*data->env)->FindClass (data->env, "org/libelektra/Key");
if (data->clsKey == 0)
{
ELEKTRA_SET_INTERFACE_ERROR (errorKey, "Cannot find class Key");
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (errorKey, "Cannot find class Key");
return -1;
}

data->clsKeySet = (*data->env)->FindClass (data->env, "org/libelektra/KeySet");
if (data->clsKeySet == 0)
{
ELEKTRA_SET_INTERFACE_ERROR (errorKey, "Cannot find class KeySet");
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (errorKey, "Cannot find class KeySet");
return -1;
}

data->midKeyConstr = (*data->env)->GetMethodID (data->env, data->clsKey, "<init>", "(J)V");
if (data->midKeyConstr == 0)
{
ELEKTRA_SET_INTERFACE_ERROR (errorKey, "Cannot find constructor of Key");
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (errorKey, "Cannot find constructor of Key");
return -1;
}

data->midKeySetConstr = (*data->env)->GetMethodID (data->env, data->clsKeySet, "<init>", "(J)V");
if (data->midKeySetConstr == 0)
{
ELEKTRA_SET_INTERFACE_ERROR (errorKey, "Cannot find constructor of KeySet");
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (errorKey, "Cannot find constructor of KeySet");
return -1;
}

data->midKeyRelease = (*data->env)->GetMethodID (data->env, data->clsKey, "release", "()V");
if (data->midKeyRelease == 0)
{
ELEKTRA_SET_INTERFACE_ERROR (errorKey, "Cannot find release of Key");
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (errorKey, "Cannot find release of Key");
return -1;
}

data->midKeySetRelease = (*data->env)->GetMethodID (data->env, data->clsKeySet, "release", "()V");
if (data->midKeySetRelease == 0)
{
ELEKTRA_SET_INTERFACE_ERROR (errorKey, "Cannot find release of KeySet");
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (errorKey, "Cannot find release of KeySet");
return -1;
}

jmethodID midPluginConstructor = (*data->env)->GetMethodID (data->env, data->clsPlugin, "<init>", "()V");
if (midPluginConstructor == 0)
{
ELEKTRA_SET_INTERFACE_ERROR (errorKey, "Cannot find constructor of plugin");
ELEKTRA_SET_GENERAL_RESOURCE_ERROR (errorKey, "Cannot find constructor of plugin");
return -1;
}

Expand Down
3 changes: 1 addition & 2 deletions src/plugins/line/line.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ int elektraLineGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * par

if (ret == -1)
{
// TODO: Correct?
ELEKTRA_SET_ASSERTION_ERRORF (parentKey, "could not increment array from %s", keyName (ksTail (returned)));
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "could not increment array from %s", keyName (ksTail (returned)));
ret = -1;
}
else if (feof (fp) == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/multifile/multifile.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ static Codes updateFilesGlob (Plugin * handle, MultiConfig * mc, KeySet * found,
{
if (ret == GLOB_NOSPACE)
{
ELEKTRA_SET_GENERAL_RESOURCE_ERRORF (parentKey, "glob(%s) ran out of memory", pattern);
ELEKTRA_SET_OUT_OF_MEMORY_ERRORF (parentKey, "glob(%s) ran out of memory", pattern);
}
else if (ret == GLOB_ABORTED)
{
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/path/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int validateKey (Key * key, Key * parentKey)
}
else if (keyString (key)[0] != '/')
{
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (parentKey, "Given path \"%s\" is not absolute", keyString (key));
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Given path \"%s\" is not absolute", keyString (key));
return 0;
}
int errnosave = errno;
Expand Down Expand Up @@ -211,6 +211,7 @@ static int validatePermission (Key * key, Key * parentKey)

if (canAccess != 0)
{
// No Resource error per se because related to the specification check!
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (parentKey, "User %s does not have required permission (%s) on %s", name, modes,
validPath);
return -1;
Expand Down
Loading

0 comments on commit 487b8ac

Please sign in to comment.