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

Commit

Permalink
error: Improvements part 7
Browse files Browse the repository at this point in the history
  • Loading branch information
ZronekM committed Jun 23, 2019
1 parent c25d5ec commit 8f4da8a
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 72 deletions.
4 changes: 2 additions & 2 deletions src/include/kdbmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
"root. Errno: %s", \
keyString (parentKey), strerror (errno)); \
else \
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Could not open file %s for writing %s", keyString (parentKey), \
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Could not open file %s for writing. Reason: %s", keyString (parentKey), \
strerror (errno)); \
} while (0)

#define ELEKTRA_MALLOC_ERROR(key, size) ELEKTRA_SET_OUT_OF_MEMORY_ERRORF (key, "Unable to allocate %zu bytes.", size);
#define ELEKTRA_MALLOC_ERROR(key, size) ELEKTRA_SET_OUT_OF_MEMORY_ERRORF (key, "Unable to allocate %zu bytes", size);

/**
* @brief Sets error if info != returned
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/augeas/augeas.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ int elektraAugeasGet (Plugin * handle, KeySet * returned, Key * parentKey)
if (content == 0)
{
fclose (fh);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Error while reading file: %s", strerror (errno));
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Error while reading file. Reason: %s", strerror (errno));
}

/* convert the string into an augeas tree */
Expand Down Expand Up @@ -576,7 +576,7 @@ int elektraAugeasSet (Plugin * handle, KeySet * returned, Key * parentKey)
if (content == 0)
{
fclose (fh);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Error while reading file: %s", strerror (errno));
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Error while reading file. Reason: %s", strerror (errno));
}

/* convert the string into an augeas tree */
Expand All @@ -603,7 +603,7 @@ int elektraAugeasSet (Plugin * handle, KeySet * returned, Key * parentKey)
ret = saveFile (augeasHandle, fh);
fclose (fh);

if (ret < 0) ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Could not open file for writing: %s", strerror (errno));
if (ret < 0) ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Could not open file for writing. Reason: %s", strerror (errno));

errno = errnosave;
return 1;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/blockresolver/blockresolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ int elektraBlockresolverSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned E
}
if (buf.st_mtime > data->mtime)
{
ELEKTRA_SET_CONFLICTING_STATE_ERRORF (parentKey, "%s has been modified", data->realFile);
ELEKTRA_SET_CONFLICTING_STATE_ERRORF (parentKey, "File '%s' has been modified", data->realFile);
return -1;
}
FILE * fout = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/boolean/boolean.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ int elektraBooleanSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA
(keyGetMeta (key, "boolean/invalid")))
{
keySetMeta (key, "boolean/invalid", 0);
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (parentKey, "%s is not a valid boolean value",
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (parentKey, "String '%s' is not a valid boolean value",
keyString (originalValue));
retVal = -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/cache/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ int elektraCacheSet (Plugin * handle, KeySet * returned, Key * parentKey)
{
if (rename (tmpFile, cacheFileName) == -1)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Could not rename file. Errno: %s", strerror (errno));
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Could not rename file. Reason: %s", strerror (errno));
goto error;
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/cachefilter/cachefilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int elektraCachefilterSet (Plugin * handle, KeySet * returned, Key * parentKey)
if (cache == NULL)
{
// TODO: Solution (Call kdbGet() to initialize Cache)
ELEKTRA_SET_INTERFACE_ERROR (parentKey, "Cache was not initialized.");
ELEKTRA_SET_INTERFACE_ERROR (parentKey, "Cache was not initialized");
return -1; // did not call kdbGet() before and therefore
// also no elektraCachefilterGet()
}
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/crypto/botan_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static int getKeyIvForEncryption (KeySet * config, Key * errorKey, Key * masterK
}
catch (std::exception const & e)
{
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to create a cryptographic key for encryption because: %s", e.what ());
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to create a cryptographic key for encryption. Reason: %s", e.what ());
return -1;
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ static int getKeyIvForDecryption (KeySet * config, Key * errorKey, Key * masterK
}
catch (std::exception const & e)
{
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to restore the cryptographic key for decryption because: %s", e.what ());
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to restore the cryptographic key for decryption. Reason: %s", e.what ());
return -1;
}
}
Expand All @@ -152,7 +152,7 @@ int elektraCryptoBotanInit (Key * errorKey)
}
catch (std::exception const & e)
{
ELEKTRA_SET_PLUGIN_MISBEHAVIOR_ERRORF (errorKey, "Botan initialization failed: %s", e.what ());
ELEKTRA_SET_PLUGIN_MISBEHAVIOR_ERRORF (errorKey, "Botan initialization failed. Reason: %s", e.what ());
return -1; // failure
}
return 1; // success
Expand Down Expand Up @@ -236,7 +236,7 @@ int elektraCryptoBotanEncrypt (KeySet * pluginConfig, Key * k, Key * errorKey, K
}
catch (std::exception const & e)
{
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Encryption failed because: %s", e.what ());
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Encryption failed. Reason: %s", e.what ());
elektraFree (salt);
return -1; // failure
}
Expand Down Expand Up @@ -308,7 +308,7 @@ int elektraCryptoBotanDecrypt (KeySet * pluginConfig, Key * k, Key * errorKey, K
}
catch (std::exception const & e)
{
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Decryption failed because: %s", e.what ());
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Decryption failed. Reason: %s", e.what ());
return -1; // failure
}

Expand Down Expand Up @@ -338,7 +338,7 @@ char * elektraCryptoBotanCreateRandomString (Key * errorKey, const kdb_unsigned_
}
catch (std::exception const & e)
{
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to generate random string because: %s", e.what ());
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to generate random string. Reason: %s", e.what ());
return 0;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/crypto/gcrypt_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static int getKeyIvForEncryption (KeySet * config, Key * errorKey, Key * masterK
if ((gcry_err = gcry_kdf_derive (keyValue (masterKey), keyGetValueSize (masterKey), GCRY_KDF_PBKDF2, GCRY_MD_SHA512, salt,
sizeof (salt), iterations, KEY_BUFFER_SIZE, keyBuffer)))
{
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to create a cryptographic key for encryption because: %s",
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to create a cryptographic key for encryption. Reason: %s",
gcry_strerror (gcry_err));
return -1;
}
Expand Down Expand Up @@ -114,7 +114,7 @@ static int getKeyIvForDecryption (KeySet * config, Key * errorKey, Key * masterK
if ((gcry_err = gcry_kdf_derive (keyValue (masterKey), keyGetValueSize (masterKey), GCRY_KDF_PBKDF2, GCRY_MD_SHA512, saltBuffer,
saltBufferLen, iterations, KEY_BUFFER_SIZE, keyBuffer)))
{
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to restore the cryptographic key for decryption because: %s",
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to restore the cryptographic key for decryption. Reason: %s",
gcry_strerror (gcry_err));
return -1;
}
Expand Down Expand Up @@ -234,7 +234,7 @@ int elektraCryptoGcryHandleCreate (elektraCryptoHandle ** handle, KeySet * confi
memset (keyBuffer, 0, sizeof (keyBuffer));
memset (ivBuffer, 0, sizeof (ivBuffer));
// TODO: Correct??
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to create handle because: %s", gcry_strerror (gcry_err));
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Failed to create handle. Reason: %s", gcry_strerror (gcry_err));
gcry_cipher_close (**handle);
elektraFree (*handle);
(*handle) = NULL;
Expand Down Expand Up @@ -318,7 +318,7 @@ int elektraCryptoGcryEncrypt (elektraCryptoHandle * handle, Key * k, Key * error
if (gcry_err != 0)
{
// TODO: Correct??
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Encryption failed because: %s", gcry_strerror (gcry_err));
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Encryption failed. Reason: %s", gcry_strerror (gcry_err));
memset (output, 0, outputLen);
elektraFree (output);
elektraFree (salt);
Expand All @@ -334,7 +334,7 @@ int elektraCryptoGcryEncrypt (elektraCryptoHandle * handle, Key * k, Key * error
if (gcry_err != 0)
{
// TODO: Correct??
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Encryption failed because: %s", gcry_strerror (gcry_err));
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Encryption failed. Reason: %s", gcry_strerror (gcry_err));
memset (output, 0, outputLen);
elektraFree (output);
elektraFree (salt);
Expand Down Expand Up @@ -389,7 +389,7 @@ int elektraCryptoGcryDecrypt (elektraCryptoHandle * handle, Key * k, Key * error
gcry_err = gcry_cipher_decrypt (*handle, output, payloadLen, NULL, 0);
if (gcry_err != 0)
{
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Decryption failed because: %s", gcry_strerror (gcry_err));
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "Decryption failed. Reason: %s", gcry_strerror (gcry_err));
memset (output, 0, payloadLen);
elektraFree (output);
return -1;
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/crypto/gpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgGetBinary) (char ** gpgBin, KeySet * conf, Key *
}

// no GPG for us :-(
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "No gpg binary found. Please make sure GnuPG is installed and executable.");
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "No gpg binary found. Please make sure GnuPG is installed and executable");
return -1;
}

Expand Down Expand Up @@ -658,7 +658,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgK
{
case -1:
// fork() failed
ELEKTRA_SET_RESOURCE_ERRORF (errorKey, "Fork failed with errno: %s", strerror (errno));
ELEKTRA_SET_RESOURCE_ERRORF (errorKey, "Fork failed. Reason: %s", strerror (errno));
closePipe (pipe_stdin);
closePipe (pipe_stdout);
closePipe (pipe_stderr);
Expand Down Expand Up @@ -718,7 +718,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgK
{
if (write (pipe_stdin[1], keyValue (msgKey), sendMessageSize) != sendMessageSize)
{
ELEKTRA_SET_RESOURCE_ERROR (errorKey, "The communication with the GPG process failed.");
ELEKTRA_SET_RESOURCE_ERROR (errorKey, "The communication with the GPG process failed");
closePipe (pipe_stdin);
closePipe (pipe_stdout);
closePipe (pipe_stderr);
Expand Down Expand Up @@ -748,19 +748,19 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgK

case 1:
// bad signature
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "GPG reported a bad signature. errno: %s", strerror (errno));
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "GPG reported a bad signature. Reason: %s", strerror (errno));
break;

case GPG_CALL_DUP_STDIN:
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "Failed to redirect stdin.");
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "Failed to redirect stdin");
break;

case GPG_CALL_DUP_STDOUT:
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "Failed to redirect stdout.");
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "Failed to redirect stdout");
break;

case GPG_CALL_DUP_STDERR:
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "Failed to redirect stderr.");
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "Failed to redirect stderr");
break;

case GPG_CALL_EXECV:
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/crypto/openssl_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ int elektraCryptoOpenSSLHandleCreate (elektraCryptoHandle ** handle, KeySet * co
{
keyDel (key);
keyDel (iv);
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "Failed to create handle! Invalid key length.");
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "Failed to create handle! Invalid key length");
return -1;
}

Expand All @@ -208,7 +208,7 @@ int elektraCryptoOpenSSLHandleCreate (elektraCryptoHandle ** handle, KeySet * co
keyDel (key);
keyDel (iv);

ELEKTRA_SET_VALIDATION_SYNTACTIC_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 Expand Up @@ -468,7 +468,7 @@ int elektraCryptoOpenSSLDecrypt (elektraCryptoHandle * handle, Key * k, Key * er
plaintextLen = BIO_get_mem_data (decrypted, &plaintext);
if (plaintextLen < headerLen)
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "Decryption error! header data is incomplete.");
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "Decryption error! header data is incomplete");
goto error;
}

Expand All @@ -482,7 +482,7 @@ int elektraCryptoOpenSSLDecrypt (elektraCryptoHandle * handle, Key * k, Key * er
if (contentLen > (plaintextLen - headerLen))
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (
errorKey, "Content length is bigger than amount of decrypted data. Data is possibly corrupted.");
errorKey, "Content length is bigger than amount of decrypted data. Data is possibly corrupted");
goto error;
}

Expand Down
12 changes: 6 additions & 6 deletions src/plugins/curlget/curlget.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ int elektraCurlgetSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA
res = curl_easy_perform (curl);
if (res != CURLE_OK)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (HTTP PUT) failed: %s",
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (HTTP PUT) failed. Reason: %s",
curl_easy_strerror (res));
retval = -1;
}
Expand All @@ -846,7 +846,7 @@ int elektraCurlgetSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA
res = curl_easy_perform (curl);
if (res != CURLE_OK)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (HTTP PUT) failed: %s",
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (HTTP PUT) failed. Reason: %s",
curl_easy_strerror (res));
retval = -1;
}
Expand Down Expand Up @@ -883,7 +883,7 @@ int elektraCurlgetSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA
res = curl_easy_perform (curl);
if (res != CURLE_OK)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (FTP PUT) failed: %s",
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (FTP PUT) failed. Reason: %s",
curl_easy_strerror (res));
retval = -1;
}
Expand All @@ -909,10 +909,10 @@ int elektraCurlgetSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA
if (res != CURLE_OK)
{
if (data->putProto == PROTO_SCP)
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (SCP) failed: %s",
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (SCP) failed. Reason: %s",
curl_easy_strerror (res));
else if (data->putProto == PROTO_SFTP)
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (SFTP) failed: %s",
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (SFTP) failed. Reason: %s",
curl_easy_strerror (res));
retval = -1;
}
Expand All @@ -929,7 +929,7 @@ int elektraCurlgetSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA
res = curl_easy_perform (curl);
if (res != CURLE_OK)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (default) failed: %s",
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Curl upload (default) . Reason: %s",
curl_easy_strerror (res));
retval = -1;
}
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/date/date.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static int validateKey (Key * key, Key * parentKey)
rc = formatStringValidation (date, formatString);
if (rc == -1)
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "%s doesn't match format string %s", date, formatString);
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Date '%s' doesn't match format string %s", date, formatString);
rc = 0;
}
}
Expand All @@ -421,10 +421,10 @@ static int validateKey (Key * key, Key * parentKey)
if (rc == -1)
{
if (formatString)
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "%s doesn't match iso specification %s", date,
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Date '%s' doesn't match iso specification %s", date,
formatString);
else
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "%s is not a valid ISO8601 date", date);
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Date '%s' is not a valid ISO8601 date", date);
rc = 0;
}
else if (rc == 0)
Expand All @@ -437,7 +437,7 @@ static int validateKey (Key * key, Key * parentKey)
rc = rfc2822StringValidation (date);
if (rc == -1)
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "%s doesn't match rfc2822 specification", date);
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Date '%s' doesn't match rfc2822 specification", date);
rc = 0;
}
}
Expand All @@ -446,7 +446,7 @@ static int validateKey (Key * key, Key * parentKey)
rc = rfc822StringValidation (date);
if (rc == -1)
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "%s doesn't match format string %s", date, formatString);
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Date '%s' doesn't match format string %s", date, formatString);
rc = 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/enum/enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static int validateKey (Key * key, Key * parentKey)
rc = validateWithArray (key);
if (!rc)
{
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (parentKey, "Validation of key '%s' with string '%s' failed.", keyName (key),
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (parentKey, "Validation of key '%s' with string '%s' failed", keyName (key),
keyString (key));
}
return rc;
Expand Down
Loading

0 comments on commit 8f4da8a

Please sign in to comment.