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

Commit

Permalink
error: migrated to fixed macro names
Browse files Browse the repository at this point in the history
  • Loading branch information
ZronekM committed Jun 22, 2019
1 parent bd4f196 commit 339d34d
Show file tree
Hide file tree
Showing 91 changed files with 959 additions and 1,054 deletions.
4 changes: 2 additions & 2 deletions doc/tutorials/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ Basically the implementation of `elektraLineSet` can be described with the follo
// open the file
if (error)
{
ELEKTRA_SET_ERROR(ELEKTRA_ERROR_RESOURCE, parentKey, keyString(parentKey));
ELEKTRA_SET_RESOURCE_ERROR( parentKey, keyString(parentKey));
}
for (/* each key */)
{
Expand Down Expand Up @@ -404,7 +404,7 @@ int elektraLineCheckConfig (Key * errorKey, KeySet * conf)
const char * value = keyString (cur);
if (strlen (value) > 3)
{
ELEKTRA_SET_ERRORF (ELEKTRA_ERROR_PARSING, errorKey,
ELEKTRA_SET_PARSING_ERRORF ( errorKey,
"value %s is more than 3 characters long",
value);
return -1; // The configuration was not OK and could not be fixed
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/cpp/include/kdbplugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Delegator
catch (const char * msg)
{
#ifdef KDBERRORS_H
ELEKTRA_ADD_WARNINGF (ELEKTRA_WARNING_INSTALLATION, errorKey, "Could not create C++ plugin: %s", msg);
ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Could not create C++ plugin: %s", msg);
#endif
return -1;
}
Expand Down
40 changes: 27 additions & 13 deletions src/error/exporterrors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,26 @@ static ostream & printKDBErrors (ostream & os, parse_t & p)
<< endl
<< "#ifdef __cplusplus" << endl
<< " using namespace ckdb;" << endl
<< endl
<< "#endif" << endl
<< "#define ELEKTRA_SET_ERROR(number, key, text) ELEKTRA_SET_ERROR_HELPER\\" << endl
<< " (number, key, text, __FILE__, __LINE__)" << endl
<< endl
<< "#define ELEKTRA_SET_ERROR_HELPER(number, key, text, file, line) ELEKTRA_SET_ERROR_HELPER_HELPER\\" << endl
<< endl;
os << endl << endl;
os << "#endif" << endl;

for (size_t i = 1; i < p.size (); ++i)
{
os << "#define ELEKTRA_SET_" << p[i]["macro"] << "_ERROR(key, text) ELEKTRA_SET_ERROR_HELPER\\" << endl;
os << " (" << p[i]["number"] << ", key, text, __FILE__, __LINE__)" << endl;
os << "#define ELEKTRA_SET_" << p[i]["macro"] << "_ERRORF(key, text, ...) ELEKTRA_SET_ERRORF_HELPER\\" << endl;
os << " (" << p[i]["number"] << ", key, text, __FILE__, __LINE__, __VA_ARGS__)" << endl << endl;

os << "#define ELEKTRA_ADD_" << p[i]["macro"] << "_WARNING(key, text) ELEKTRA_ADD_WARNING_HELPER\\" << endl;
os << " (" << p[i]["number"] << ", key, text, __FILE__, __LINE__)" << endl;
os << "#define ELEKTRA_ADD_" << p[i]["macro"] << "_WARNINGF(key, text, ...) ELEKTRA_ADD_WARNINGF_HELPER\\" << endl;
os << " (" << p[i]["number"] << ", key, text, __FILE__, __LINE__, __VA_ARGS__)" << endl << endl;
}
// << "#define ELEKTRA_SET_ERROR(number, key, text) ELEKTRA_SET_ERROR_HELPER\\" << endl
// << " (number, key, text, __FILE__, __LINE__)" << endl
// << endl
os << "#define ELEKTRA_SET_ERROR_HELPER(number, key, text, file, line) ELEKTRA_SET_ERROR_HELPER_HELPER\\" << endl
<< " (number, key, text, file, line)" << endl
<< endl
<< "#define ELEKTRA_SET_ERROR_HELPER_HELPER(number, key, text, file, line) do {ELEKTRA_LOG (\"Add Error %s: %s\", "
Expand All @@ -53,9 +67,9 @@ static ostream & printKDBErrors (ostream & os, parse_t & p)
<< " (key, text, file, #line); } while (0)" << endl
<< endl
<< endl
<< "#define ELEKTRA_ADD_WARNING(number, key, text) ELEKTRA_ADD_WARNING_HELPER\\" << endl
<< " (number, key, text, __FILE__, __LINE__)" << endl
<< "" << endl
// << "#define ELEKTRA_ADD_WARNING(number, key, text) ELEKTRA_ADD_WARNING_HELPER\\" << endl
// << " (number, key, text, __FILE__, __LINE__)" << endl
// << "" << endl
<< "#define ELEKTRA_ADD_WARNING_HELPER(number, key, text, file, line) ELEKTRA_ADD_WARNING_HELPER_HELPER\\" << endl
<< " (number, key, text, file, line)" << endl
<< "" << endl
Expand Down Expand Up @@ -303,20 +317,20 @@ static ostream & printKDBErrors (ostream & os, parse_t & p)
for (size_t i = 1; i < p.size (); ++i)
{
os << " if(strcmp(nr, \"" << p[i]["number"] << "\") == 0)" << endl << " {" << endl;
os << " ELEKTRA_ADD_WARNING (" << p[i]["number"] << ", parentKey, message);" << endl
os << " ELEKTRA_ADD_" << p[i]["macro"] << "_WARNING (parentKey, message);" << endl
<< " return;" << endl
<< " }" << endl;
}
os << " ELEKTRA_ADD_WARNING (01400, parentKey, \"Unkown warning code\");" << endl << "}" << endl << "" << endl;
os << " ELEKTRA_ADD_LOGICAL_WARNING (parentKey, \"Unkown warning code\");" << endl << "}" << endl << "" << endl;
os << "static inline void elektraTriggerError (const char *nr, Key *parentKey, const char *message)" << endl << "{" << endl;
for (size_t i = 1; i < p.size (); ++i)
{
os << " if(strcmp(nr, \"" << p[i]["number"] << "\") == 0)" << endl << " {" << endl;
os << " ELEKTRA_SET_ERROR (" << p[i]["number"] << ", parentKey, message);" << endl
os << " ELEKTRA_SET_" << p[i]["macro"] << "_ERROR (parentKey, message);" << endl
<< " return;" << endl
<< " }" << endl;
}
os << " ELEKTRA_SET_ERROR (01400, parentKey, \"Unkown error code\");" << endl << "}" << endl;
os << " ELEKTRA_SET_LOGICAL_ERROR (parentKey, \"Unkown error code\");" << endl << "}" << endl;

os << "#endif" << endl;
return os;
Expand Down
47 changes: 25 additions & 22 deletions src/include/kdbmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,30 @@
do \
{ \
if (errno == EACCES) \
ELEKTRA_SET_ERRORF (ELEKTRA_ERROR_RESOURCE, parentKey, \
"Insufficient permissions to open configuration file for reading. Reason: %s. You might want " \
"to retry as root or change access using chmod.", \
strerror (errno)); \
ELEKTRA_SET_RESOURCE_ERRORF ( \
parentKey, \
"Insufficient permissions to open configuration file for reading. Reason: %s. You might want " \
"to retry as root or change access using chmod.", \
strerror (errno)); \
else \
ELEKTRA_SET_ERRORF (ELEKTRA_ERROR_RESOURCE, parentKey, \
"Could not open configuration file for reading. Reason: %s", strerror (errno)); \
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Could not open configuration file for reading. Reason: %s", \
strerror (errno)); \
} while (0)

#define ELEKTRA_SET_ERROR_SET(parentKey) \
do \
{ \
if (errno == EACCES) \
ELEKTRA_SET_ERRORF (ELEKTRA_ERROR_RESOURCE, parentKey, \
"Insufficient permissions to open configuration file for writing. You might want to retry as " \
"root. Errno: %s", \
strerror (errno)); \
ELEKTRA_SET_RESOURCE_ERRORF ( \
parentKey, \
"Insufficient permissions to open configuration file for writing. You might want to retry as " \
"root. Errno: %s", \
strerror (errno)); \
else \
ELEKTRA_SET_ERRORF (ELEKTRA_ERROR_RESOURCE, parentKey, ":Could not open file for writing %s", strerror (errno)); \
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, ":Could not open file for writing %s", strerror (errno)); \
} while (0)

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

/**
* @brief Sets error 84 if info != returned
Expand All @@ -80,27 +82,28 @@
Key * c = ksNext (info); \
if (!c) \
{ \
ELEKTRA_SET_ERRORF (ELEKTRA_ERROR_INSTALLATION, error, \
"Read only plugin, kdbSet not supported but the key %s (value %s) was added", \
keyName (k), keyString (k)); \
ELEKTRA_SET_INSTALLATION_ERRORF ( \
error, "Read only plugin, kdbSet not supported but the key %s (value %s) was added", keyName (k), \
keyString (k)); \
ksDel (info); \
return -1; \
} \
if (strcmp (keyName (k), keyName (c)) || strcmp (keyString (k), keyString (c))) \
{ \
ELEKTRA_SET_ERRORF (ELEKTRA_ERROR_INSTALLATION, error, \
"Read only plugin, kdbSet not supported but the key %s (expected %s) was modified to " \
"%s (expected %s)", \
keyName (k), keyName (c), keyString (k), keyString (c)); \
ELEKTRA_SET_INSTALLATION_ERRORF ( \
error, \
"Read only plugin, kdbSet not supported but the key %s (expected %s) was modified to " \
"%s (expected %s)", \
keyName (k), keyName (c), keyString (k), keyString (c)); \
ksDel (info); \
return -1; \
} \
} \
if ((k = ksNext (info)) != 0) \
{ \
ELEKTRA_SET_ERRORF (ELEKTRA_ERROR_INSTALLATION, error, \
"Read only plugin, kdbSet not supported but the key %s (value %s) was removed", keyName (k), \
keyString (k)); \
ELEKTRA_SET_INSTALLATION_ERRORF (error, \
"Read only plugin, kdbSet not supported but the key %s (value %s) was removed", \
keyName (k), keyString (k)); \
ksDel (info); \
return -1; \
} \
Expand Down
21 changes: 7 additions & 14 deletions src/libs/elektra/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int elektraBackendSetMountpoint (Backend * backend, KeySet * elektraConfig, Key

if (!foundMountpoint)
{
ELEKTRA_ADD_WARNINGF (ELEKTRA_WARNING_INSTALLATION, errorKey, "Could not find mountpoint within root %s", keyName (root));
ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Could not find mountpoint within root %s", keyName (root));
return -1;
}

Expand All @@ -91,8 +91,8 @@ int elektraBackendSetMountpoint (Backend * backend, KeySet * elektraConfig, Key

if (!backend->mountpoint)
{
ELEKTRA_ADD_WARNINGF (ELEKTRA_WARNING_INSTALLATION, errorKey, "Could not create mountpoint with name %s and value %s",
keyString (foundMountpoint), keyBaseName (root));
ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Could not create mountpoint with name %s and value %s",
keyString (foundMountpoint), keyBaseName (root));
return -1;
}

Expand Down Expand Up @@ -201,9 +201,7 @@ Backend * backendOpen (KeySet * elektraConfig, KeySet * modules, KeySet * global
if (elektraProcessPlugins (backend->errorplugins, modules, referencePlugins, cut, systemConfig, global,
errorKey) == -1)
{
if (!failure)
ELEKTRA_ADD_WARNING (ELEKTRA_WARNING_INSTALLATION, errorKey,
"elektraProcessPlugins for error failed");
if (!failure) ELEKTRA_ADD_INSTALLATION_WARNING (errorKey, "elektraProcessPlugins for error failed");
failure = 1;
}
}
Expand All @@ -212,9 +210,7 @@ Backend * backendOpen (KeySet * elektraConfig, KeySet * modules, KeySet * global
if (elektraProcessPlugins (backend->getplugins, modules, referencePlugins, cut, systemConfig, global,
errorKey) == -1)
{
if (!failure)
ELEKTRA_ADD_WARNING (ELEKTRA_WARNING_INSTALLATION, errorKey,
"elektraProcessPlugins for get failed");
if (!failure) ELEKTRA_ADD_INSTALLATION_WARNING (errorKey, "elektraProcessPlugins for get failed");
failure = 1;
}
}
Expand All @@ -228,18 +224,15 @@ Backend * backendOpen (KeySet * elektraConfig, KeySet * modules, KeySet * global
if (elektraProcessPlugins (backend->setplugins, modules, referencePlugins, cut, systemConfig, global,
errorKey) == -1)
{
if (!failure)
ELEKTRA_ADD_WARNING (ELEKTRA_WARNING_INSTALLATION, errorKey,
"elektraProcessPlugins for set failed");
if (!failure) ELEKTRA_ADD_INSTALLATION_WARNING (errorKey, "elektraProcessPlugins for set failed");
failure = 1;
}
}
else
{
// no one cares about that config
if (!failure)
ELEKTRA_ADD_WARNINGF (ELEKTRA_WARNING_INSTALLATION, errorKey, "Unrecognised Config Tree: %s",
keyBaseName (cur));
ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Unrecognised Config Tree: %s", keyBaseName (cur));
ksDel (cut);
}
}
Expand Down
Loading

0 comments on commit 339d34d

Please sign in to comment.