From cdf52e2dc0f4b7da4fec13c296cf21b255159fdf Mon Sep 17 00:00:00 2001 From: Michael Zronek Date: Fri, 26 Apr 2019 12:36:04 +0200 Subject: [PATCH] error: error message improvements, compilation fix, minor improvements --- src/libs/elektra/backend.c | 7 +++++-- src/libs/elektra/kdb.c | 6 +++--- src/libs/elektra/plugin.c | 4 ++-- src/libs/highlevel/elektra_error.c | 4 ++-- src/libs/opts/opts.c | 1 + src/plugins/augeas/augeas.c | 3 +-- src/plugins/crypto/gcrypt_operations.c | 4 ++-- src/plugins/crypto/gpg.c | 4 ++-- src/plugins/crypto/helper.c | 4 ++-- src/plugins/crypto/openssl_operations.c | 7 ++++--- src/plugins/gpgme/gpgme.c | 2 +- src/plugins/network/network.c | 4 ++-- src/plugins/path/path.c | 12 ++++++------ src/plugins/quickdump/quickdump.c | 6 +++--- src/plugins/quickdump/readv1.c | 6 +++--- src/plugins/resolver/resolver.c | 8 ++++---- src/plugins/yamlcpp/yamlcpp.cpp | 2 +- 17 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/libs/elektra/backend.c b/src/libs/elektra/backend.c index 31a094bc6fa..ef02ec2e78b 100644 --- a/src/libs/elektra/backend.c +++ b/src/libs/elektra/backend.c @@ -232,8 +232,11 @@ Backend * backendOpen (KeySet * elektraConfig, KeySet * modules, KeySet * global { // no one cares about that config if (!failure) - // TODO: Correct? - ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Unrecognised Config Tree: %s", keyBaseName (cur)); + ELEKTRA_ADD_INSTALLATION_WARNINGF ( + errorKey, + "Found garbage within the backend configuration. found: %s but expected config, " + "setplugins, getplugins, errorplugins or mountpoint", + keyBaseName (cur)); ksDel (cut); } } diff --git a/src/libs/elektra/kdb.c b/src/libs/elektra/kdb.c index 6f0ab922ef5..9fe61d40ae7 100644 --- a/src/libs/elektra/kdb.c +++ b/src/libs/elektra/kdb.c @@ -1304,7 +1304,7 @@ static void elektraSetCommit (Split * split, Key * parentKey) if (ret == -1) { ELEKTRA_ADD_ASSERTION_WARNINGF (parentKey, "Error during commit. This means backend is broken: %s", - keyName (backend->mountpoint)); + keyName (backend->mountpoint)); } } } @@ -1336,7 +1336,7 @@ static void elektraSetRollback (Split * split, Key * parentKey) if (ret == -1) { ELEKTRA_ADD_ASSERTION_WARNINGF (parentKey, "Error during rollback. This means backend is broken: %s", - keyName (backend->mountpoint)); + keyName (backend->mountpoint)); } } } @@ -1576,7 +1576,7 @@ int kdbSet (KDB * handle, KeySet * ks, Key * parentKey) if (!found) { ELEKTRA_ADD_ASSERTION_WARNINGF (parentKey, "Error key %s not found in keyset even though it was found before", - keyName (errorKey)); + keyName (errorKey)); } } diff --git a/src/libs/elektra/plugin.c b/src/libs/elektra/plugin.c index 00084f58e27..bfc051e512a 100644 --- a/src/libs/elektra/plugin.c +++ b/src/libs/elektra/plugin.c @@ -227,8 +227,8 @@ int elektraProcessPlugins (Plugin ** plugins, KeySet * modules, KeySet * referen } else { - // TODO: Correct? - ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Unknown additional entries in plugin: %s", keyString (cur)); + ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Unknown additional entries in plugin configuration: %s", + keyString (cur)); } } diff --git a/src/libs/highlevel/elektra_error.c b/src/libs/highlevel/elektra_error.c index 2f82382bd2a..1e14cf74cfc 100644 --- a/src/libs/highlevel/elektra_error.c +++ b/src/libs/highlevel/elektra_error.c @@ -159,7 +159,7 @@ ElektraError * elektraErrorFromKey (Key * key) ElektraError * elektraErrorKeyNotFound (const char * keyname) { char * description = elektraFormat ("The key '%s' could not be found.", keyname); - ElektraError * error = elektraErrorCreate (ELEKTRA_ERROR_LOGICAL, description, "highlevel", "unknown", 0); + ElektraError * error = elektraErrorCreate (ELEKTRA_ERROR_ASSERTION, description, "highlevel", "unknown", 0); elektraFree (description); return error; } @@ -176,7 +176,7 @@ ElektraError * elektraErrorWrongType (const char * keyname, KDBType expectedType ElektraError * elektraErrorNullError (const char * function) { char * description = elektraFormat ("The value passed to the ElektraError ** argument of %s was NULL.", function); - ElektraError * error = elektraErrorCreate (ELEKTRA_ERROR_LOGICAL, description, "highlevel", "unknown", 0); + ElektraError * error = elektraErrorCreate (ELEKTRA_ERROR_ASSERTION, description, "highlevel", "unknown", 0); elektraFree (description); return error; } diff --git a/src/libs/opts/opts.c b/src/libs/opts/opts.c index 0c23656929f..1e718828d7f 100644 --- a/src/libs/opts/opts.c +++ b/src/libs/opts/opts.c @@ -14,6 +14,7 @@ #include #include #include +#include #include diff --git a/src/plugins/augeas/augeas.c b/src/plugins/augeas/augeas.c index 244ed1c30b4..9e2f448dc26 100644 --- a/src/plugins/augeas/augeas.c +++ b/src/plugins/augeas/augeas.c @@ -105,8 +105,7 @@ int elektraAugeasGenConf (KeySet * ks, Key * errorKey ELEKTRA_UNUSED) } else { - // TODO: Correct? - ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Could not glob %s", f); + ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Could not glob %s because of augeas", f); retval = -1; } return retval; diff --git a/src/plugins/crypto/gcrypt_operations.c b/src/plugins/crypto/gcrypt_operations.c index 57715df5a5d..f4ec8500485 100644 --- a/src/plugins/crypto/gcrypt_operations.c +++ b/src/plugins/crypto/gcrypt_operations.c @@ -73,7 +73,7 @@ static int getKeyIvForEncryption (KeySet * config, Key * errorKey, Key * masterK { // TODO: Correct? ELEKTRA_SET_ASSERTION_ERRORF (errorKey, "Failed to create a cryptographic key for encryption because: %s", - gcry_strerror (gcry_err)); + gcry_strerror (gcry_err)); return -1; } @@ -116,7 +116,7 @@ static int getKeyIvForDecryption (KeySet * config, Key * errorKey, Key * masterK saltBufferLen, iterations, KEY_BUFFER_SIZE, keyBuffer))) { ELEKTRA_SET_ASSERTION_ERRORF (errorKey, "Failed to restore the cryptographic key for decryption because: %s", - gcry_strerror (gcry_err)); + gcry_strerror (gcry_err)); return -1; } diff --git a/src/plugins/crypto/gpg.c b/src/plugins/crypto/gpg.c index 7261bbb863d..09eebb748c2 100644 --- a/src/plugins/crypto/gpg.c +++ b/src/plugins/crypto/gpg.c @@ -659,7 +659,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgK case -1: // fork() failed // TODO: Correct? - ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "fork failed"); + ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "fork failed with errno: %s", strerror (errno)); closePipe (pipe_stdin); closePipe (pipe_stdout); closePipe (pipe_stderr); @@ -751,7 +751,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgK case 1: // bad signature // TODO: Correct? - ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "GPG reported a bad signature"); + ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "GPG reported a bad signature. errno: %s", strerror (errno)); break; case GPG_CALL_DUP_STDIN: diff --git a/src/plugins/crypto/helper.c b/src/plugins/crypto/helper.c index 49d6e6f7b6b..3e2a98c80af 100644 --- a/src/plugins/crypto/helper.c +++ b/src/plugins/crypto/helper.c @@ -120,7 +120,7 @@ int ELEKTRA_PLUGIN_FUNCTION (getSaltFromMetakey) (Key * errorKey, Key * k, kdb_o int result = ELEKTRA_PLUGIN_FUNCTION (base64Decode) (errorKey, keyString (meta), salt, &saltLenInternal); if (result == -1) { - ELEKTRA_SET_SEMANTIC_VALIDATION_ERROR (errorKey, "Salt was not stored Base64 encoded."); + ELEKTRA_SET_VALIDATION_SEMANTIC_ERROR (errorKey, "Salt was not stored Base64 encoded."); return -1; } else if (result == -2) @@ -174,7 +174,7 @@ int ELEKTRA_PLUGIN_FUNCTION (getSaltFromPayload) (Key * errorKey, Key * k, kdb_o { // TODO: Correct? ELEKTRA_SET_ASSERTION_ERRORF (errorKey, "restored salt has invalid length of %u (payload length is: %zu)", restoredSaltLen, - payloadLen); + payloadLen); if (salt) *salt = NULL; return -1; } diff --git a/src/plugins/crypto/openssl_operations.c b/src/plugins/crypto/openssl_operations.c index 430e785ce46..9ffb53cff76 100644 --- a/src/plugins/crypto/openssl_operations.c +++ b/src/plugins/crypto/openssl_operations.c @@ -90,8 +90,8 @@ static int getKeyIvForEncryption (KeySet * config, Key * errorKey, Key * masterK { // TODO: Correct? ELEKTRA_SET_ASSERTION_ERRORF (errorKey, - "Failed to create a cryptographic key for encryption. Libcrypto returned error code: %lu", - ERR_get_error ()); + "Failed to create a cryptographic key for encryption. Libcrypto returned error code: %lu", + ERR_get_error ()); pthread_mutex_unlock (&mutex_ssl); return -1; } @@ -529,7 +529,8 @@ char * elektraCryptoOpenSSLCreateRandomString (Key * errorKey, const kdb_unsigne if (!RAND_bytes (buffer, length)) { // TODO: Correct? - ELEKTRA_SET_ASSERTION_ERRORF (errorKey, "Failed to generate random string. libcrypto error code was: %lu", ERR_get_error ()); + ELEKTRA_SET_ASSERTION_ERRORF (errorKey, "Failed to generate random string. libcrypto error code was: %lu", + ERR_get_error ()); pthread_mutex_unlock (&mutex_ssl); return NULL; } diff --git a/src/plugins/gpgme/gpgme.c b/src/plugins/gpgme/gpgme.c index b53f0f6e640..8b91becb21f 100644 --- a/src/plugins/gpgme/gpgme.c +++ b/src/plugins/gpgme/gpgme.c @@ -185,7 +185,7 @@ static gpgme_key_t * extractRecipientFromPluginConfig (KeySet * config, Key * er { // TODO: Correct? ELEKTRA_SET_ASSERTION_ERRORF (errorKey, "Failed to receive the GPG key because: %s", - gpgme_strerror (err)); + gpgme_strerror (err)); elektraGpgmeKeylistFree (&list); return NULL; } diff --git a/src/plugins/network/network.c b/src/plugins/network/network.c index b40922efa8d..11e470dfa46 100644 --- a/src/plugins/network/network.c +++ b/src/plugins/network/network.c @@ -75,8 +75,8 @@ int elektraPortInfo (Key * toCheck, Key * parentKey) service = getservbyname (keyString (toCheck), NULL); // NULL means we accept both tcp and udp if (service == NULL) { - ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (parentKey, "Could not find service with name %s on key %s", - keyString (toCheck), keyName (toCheck)); + ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (parentKey, "Could not find service with name %s on key %s. Errno: %s", + keyString (toCheck), keyName (toCheck), strerror (errno)); return -1; } portNumberNetworkByteOrder = service->s_port; diff --git a/src/plugins/path/path.c b/src/plugins/path/path.c index b7aaee663de..e43266ad0fe 100644 --- a/src/plugins/path/path.c +++ b/src/plugins/path/path.c @@ -204,8 +204,8 @@ static int validatePermission (Key * key, Key * parentKey) if (euidResult != 0 || egidResult != 0) { ELEKTRA_SET_ASSERTION_ERROR (parentKey, - "There was a problem in the user switching process." - "Please report the issue at https://issues.libelektra.org"); + "There was a problem in the user switching process." + "Please report the issue at https://issues.libelektra.org"); return -1; } @@ -239,13 +239,13 @@ static int getAllGroups (Key * parentKey, uid_t currentUID, const struct passwd if (getgrouplist (p->pw_name, (int) p->pw_gid, (*groups), &ngroups) < 0) { ELEKTRA_SET_ASSERTION_ERROR (parentKey, - "There was a problem in the getting all groups for the user." - "Please report the issue at https://issues.libelektra.org"); + "There was a problem in the getting all groups for the user." + "Please report the issue at https://issues.libelektra.org"); if (seteuid (currentUID) < 0) { ELEKTRA_SET_ASSERTION_ERROR (parentKey, - "There was a problem in the user switching process." - "Please report the issue at https://issues.libelektra.org"); + "There was a problem in the user switching process." + "Please report the issue at https://issues.libelektra.org"); } return -1; } diff --git a/src/plugins/quickdump/quickdump.c b/src/plugins/quickdump/quickdump.c index 019c499ab25..33830b1e260 100644 --- a/src/plugins/quickdump/quickdump.c +++ b/src/plugins/quickdump/quickdump.c @@ -387,7 +387,7 @@ int elektraQuickdumpGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key if (sourceKey == NULL) { ELEKTRA_SET_ASSERTION_ERRORF (parentKey, "Could not copy meta data from key '%s': Key not found", - nameBuffer.string); + nameBuffer.string); keyDel (k); elektraFree (nameBuffer.string); elektraFree (metaNameBuffer.string); @@ -399,8 +399,8 @@ int elektraQuickdumpGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key if (keyCopyMeta (k, sourceKey, metaNameBuffer.string) != 1) { ELEKTRA_SET_ASSERTION_ERRORF (parentKey, - "Could not copy meta data from key '%s': Error during copy", - &nameBuffer.string[nameBuffer.offset]); + "Could not copy meta data from key '%s': Error during copy", + &nameBuffer.string[nameBuffer.offset]); keyDel (k); elektraFree (nameBuffer.string); elektraFree (metaNameBuffer.string); diff --git a/src/plugins/quickdump/readv1.c b/src/plugins/quickdump/readv1.c index 913a79c8814..eb9ff849b81 100644 --- a/src/plugins/quickdump/readv1.c +++ b/src/plugins/quickdump/readv1.c @@ -146,7 +146,7 @@ static int readVersion1 (FILE * file, KeySet * returned, Key * parentKey) if (sourceKey == NULL) { ELEKTRA_SET_ASSERTION_ERRORF (parentKey, "Could not copy meta data from key '%s': Key not found", - keyName); + keyName); keyDel (k); elektraFree (keyName); elektraFree (metaName); @@ -156,8 +156,8 @@ static int readVersion1 (FILE * file, KeySet * returned, Key * parentKey) if (keyCopyMeta (k, sourceKey, metaName) != 1) { - ELEKTRA_SET_ASSERTION_ERRORF ( - parentKey, "Could not copy meta data from key '%s': Error during copy", keyName); + ELEKTRA_SET_ASSERTION_ERRORF (parentKey, + "Could not copy meta data from key '%s': Error during copy", keyName); keyDel (k); elektraFree (keyName); elektraFree (metaName); diff --git a/src/plugins/resolver/resolver.c b/src/plugins/resolver/resolver.c index d4a11e07e67..cf159bdef5b 100644 --- a/src/plugins/resolver/resolver.c +++ b/src/plugins/resolver/resolver.c @@ -972,7 +972,7 @@ static void elektraUpdateFileTime (resolverHandle * pk, int fd, Key * parentKey) { // TODO: Correct? ELEKTRA_ADD_ASSERTION_WARNINGF (parentKey, "Could not update time stamp of \"%s\", because %s", - fd == pk->fd ? pk->filename : pk->tempfile, strerror (errno)); + fd == pk->fd ? pk->filename : pk->tempfile, strerror (errno)); } #elif defined(HAVE_FUTIMES) const struct timeval times[2] = { { pk->mtime.tv_sec, pk->mtime.tv_nsec / 1000 }, // atime @@ -982,7 +982,7 @@ static void elektraUpdateFileTime (resolverHandle * pk, int fd, Key * parentKey) { // TODO: Correct? ELEKTRA_ADD_ASSERTION_WARNINGF (parentKey, "Could not update time stamp of \"%s\", because %s", - fd == pk->fd ? pk->filename : pk->tempfile, strerror (errno)); + fd == pk->fd ? pk->filename : pk->tempfile, strerror (errno)); } #else #warning futimens/futimes not defined @@ -1061,7 +1061,7 @@ static int elektraSetCommit (resolverHandle * pk, Key * parentKey) if (fchmod (fd, pk->filemode) == -1) { ELEKTRA_ADD_ASSERTION_WARNINGF (parentKey, "Could not fchmod temporary file \"%s\" from %o to %o, because %s", - pk->tempfile, buf.st_mode, pk->filemode, strerror (errno)); + pk->tempfile, buf.st_mode, pk->filemode, strerror (errno)); } } @@ -1070,7 +1070,7 @@ static int elektraSetCommit (resolverHandle * pk, Key * parentKey) if (fchown (fd, pk->uid, pk->gid) == -1) { ELEKTRA_ADD_ASSERTION_WARNINGF (parentKey, "Could not fchown temporary file \"%s\" from %d.%d to %d.%d, because %s", - pk->tempfile, buf.st_uid, buf.st_gid, pk->uid, pk->gid, strerror (errno)); + pk->tempfile, buf.st_uid, buf.st_gid, pk->uid, pk->gid, strerror (errno)); } } diff --git a/src/plugins/yamlcpp/yamlcpp.cpp b/src/plugins/yamlcpp/yamlcpp.cpp index 9a5ca344d6a..efb6e9d58bd 100644 --- a/src/plugins/yamlcpp/yamlcpp.cpp +++ b/src/plugins/yamlcpp/yamlcpp.cpp @@ -121,7 +121,7 @@ int elektraYamlcppSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * catch (YAML::EmitterException const & exception) { ELEKTRA_SET_ASSERTION_ERRORF (parent.getKey (), "Something went wrong while emitting YAML data to file ā€œ%sā€: %s.", - parent.getString ().c_str (), exception.what ()); + parent.getString ().c_str (), exception.what ()); } parent.release ();