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

Commit

Permalink
remove ELEKTRA_ERROR_*_NAME and ELEKTRA_WARNING_*_NAME
Browse files Browse the repository at this point in the history
closes #4230
  • Loading branch information
kodebach committed Jan 28, 2022
1 parent d8b56fb commit e5ddb14
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 436 deletions.
2 changes: 2 additions & 0 deletions doc/news/_preparation_next_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ The text below summarizes updates to the [C (and C++)-based libraries](https://w
- Fix check for valid namespace in keyname creation _(@JakobWonisch)_
- Fix `keyCopyMeta` not deleting non existant keys in destination (see #3981) _(@JakobWonisch)_

- The `ELEKTRA_ERROR_*_NAME` and `ELEKTRA_WARNING_*_NAME` constants have been removed from the public API. Use `ELEKTRA_ERROR_*` and `ELEKTRA_WARNING_*` instead. _(Klemens Böswirth @kodebach)_

### <<Library1>>

- <<TODO>>
Expand Down
3 changes: 0 additions & 3 deletions src/include/kdberrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,7 @@ using KeySet = ckdb::KeySet;

#define DECLARE_ERROR_CODE(cname) \
extern const char * ELEKTRA_ERROR_##cname; \
extern const char * ELEKTRA_ERROR_##cname##_NAME; \
\
extern const char * ELEKTRA_WARNING_##cname; \
extern const char * ELEKTRA_WARNING_##cname##_NAME; \
\
void elektraSetError##cname (Key * key, const char * file, const char * line, const char * module, const char * reason, ...); \
void elektraAddWarning##cname (Key * key, const char * file, const char * line, const char * module, const char * reason, ...);
Expand Down
175 changes: 61 additions & 114 deletions src/libs/elektra/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,21 @@ static void setError (Key * key, const char * code, const char * name, const cha

#define DEFINE_ERROR_AND_WARNING(cname) \
const char * ELEKTRA_ERROR_##cname = ELEKTRA_ERROR_CODE_##cname; \
const char * ELEKTRA_ERROR_##cname##_NAME = ELEKTRA_ERROR_CODE_##cname##_NAME; \
const char * ELEKTRA_WARNING_##cname = ELEKTRA_ERROR_CODE_##cname; \
const char * ELEKTRA_WARNING_##cname##_NAME = ELEKTRA_ERROR_CODE_##cname##_NAME; \
\
void elektraSetError##cname (Key * key, const char * file, const char * line, const char * module, const char * reason, ...) \
{ \
va_list va; \
va_start (va, reason); \
setError (key, ELEKTRA_ERROR_##cname, ELEKTRA_ERROR_##cname##_NAME, file, line, module, reason, va); \
setError (key, ELEKTRA_ERROR_CODE_##cname, ELEKTRA_ERROR_CODE_##cname##_NAME, file, line, module, reason, va); \
va_end (va); \
} \
\
void elektraAddWarning##cname (Key * key, const char * file, const char * line, const char * module, const char * reason, ...) \
{ \
va_list va; \
va_start (va, reason); \
addWarning (key, ELEKTRA_WARNING_##cname, ELEKTRA_WARNING_##cname##_NAME, file, line, module, reason, va); \
addWarning (key, ELEKTRA_ERROR_CODE_##cname, ELEKTRA_ERROR_CODE_##cname##_NAME, file, line, module, reason, va); \
va_end (va); \
}

Expand All @@ -146,136 +144,85 @@ DEFINE_ERROR_AND_WARNING (CONFLICTING_STATE)
DEFINE_ERROR_AND_WARNING (VALIDATION_SYNTACTIC)
DEFINE_ERROR_AND_WARNING (VALIDATION_SEMANTIC)

#define ERROR_SPEC_KEYS(cname) \
keyNew ("system:/elektra/modules/error/specification", KEY_VALUE, "the specification of all error codes", KEY_END), \
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_##cname, KEY_END), \
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_##cname "/description", KEY_VALUE, \
ELEKTRA_ERROR_CODE_##cname##_NAME, KEY_END)

KeySet * elektraErrorSpecification (void)
{
return ksNew (30,
keyNew ("system:/elektra/modules/error/specification", KEY_VALUE, "the specification of all error codes", KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_RESOURCE, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_RESOURCE "/description", KEY_VALUE,
ELEKTRA_ERROR_CODE_RESOURCE_NAME, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_OUT_OF_MEMORY, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_OUT_OF_MEMORY "/description", KEY_VALUE,
ELEKTRA_ERROR_CODE_OUT_OF_MEMORY_NAME, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_INSTALLATION, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_INSTALLATION "/description", KEY_VALUE,
ELEKTRA_ERROR_CODE_INSTALLATION_NAME, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_INTERNAL, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_INTERNAL "/description", KEY_VALUE,
ELEKTRA_ERROR_CODE_INTERNAL_NAME, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_INTERFACE, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_INTERFACE "/description", KEY_VALUE,
ELEKTRA_ERROR_CODE_INTERFACE_NAME, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_PLUGIN_MISBEHAVIOR, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_PLUGIN_MISBEHAVIOR "/description",
KEY_VALUE, ELEKTRA_ERROR_CODE_PLUGIN_MISBEHAVIOR_NAME, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_CONFLICTING_STATE, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_CONFLICTING_STATE "/description", KEY_VALUE,
ELEKTRA_ERROR_CODE_CONFLICTING_STATE_NAME, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_VALIDATION_SYNTACTIC, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_VALIDATION_SYNTACTIC "/description",
KEY_VALUE, ELEKTRA_ERROR_CODE_VALIDATION_SYNTACTIC_NAME, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_VALIDATION_SEMANTIC, KEY_END),
keyNew ("system:/elektra/modules/error/specification/" ELEKTRA_ERROR_CODE_VALIDATION_SEMANTIC "/description",
KEY_VALUE, ELEKTRA_ERROR_CODE_VALIDATION_SEMANTIC_NAME, KEY_END),
// clang-format off
ERROR_SPEC_KEYS (RESOURCE),
ERROR_SPEC_KEYS (OUT_OF_MEMORY),
ERROR_SPEC_KEYS (INSTALLATION),
ERROR_SPEC_KEYS (INTERNAL),
ERROR_SPEC_KEYS (INTERFACE),
ERROR_SPEC_KEYS (PLUGIN_MISBEHAVIOR),
ERROR_SPEC_KEYS (CONFLICTING_STATE),
ERROR_SPEC_KEYS (VALIDATION_SYNTACTIC),
ERROR_SPEC_KEYS (VALIDATION_SEMANTIC),
// clang-format on
KS_END);
}

#define MAYBE_TRIGGER_WARNING(cname, code, pk, msg) \
do \
{ \
if (strcmp (code, ELEKTRA_ERROR_CODE_##cname) == 0) \
{ \
ELEKTRA_ADD_##cname##_WARNING (pk, msg); \
return; \
} \
} while (0)

void elektraTriggerWarnings (const char * nr, Key * parentKey, const char * message)
{
if (strcmp (nr, ELEKTRA_WARNING_RESOURCE) == 0)
{
ELEKTRA_ADD_RESOURCE_WARNING (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_WARNING_OUT_OF_MEMORY) == 0)
// OOM error is different, so check that one first
if (strcmp (nr, ELEKTRA_ERROR_CODE_OUT_OF_MEMORY) == 0)
{
ELEKTRA_ADD_OUT_OF_MEMORY_WARNING (parentKey);
return;
}
if (strcmp (nr, ELEKTRA_WARNING_INSTALLATION) == 0)
{
ELEKTRA_ADD_INSTALLATION_WARNING (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_WARNING_INTERNAL) == 0)
{
ELEKTRA_ADD_INTERNAL_WARNING (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_WARNING_INTERFACE) == 0)
{
ELEKTRA_ADD_INTERFACE_WARNING (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_WARNING_PLUGIN_MISBEHAVIOR) == 0)
{
ELEKTRA_ADD_PLUGIN_MISBEHAVIOR_WARNING (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_WARNING_CONFLICTING_STATE) == 0)
{
ELEKTRA_ADD_CONFLICTING_STATE_WARNING (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_WARNING_VALIDATION_SYNTACTIC) == 0)
{
ELEKTRA_ADD_VALIDATION_SYNTACTIC_WARNING (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_WARNING_VALIDATION_SEMANTIC) == 0)
{
ELEKTRA_ADD_VALIDATION_SEMANTIC_WARNING (parentKey, message);
return;
}

MAYBE_TRIGGER_WARNING (RESOURCE, nr, parentKey, message);
MAYBE_TRIGGER_WARNING (INSTALLATION, nr, parentKey, message);
MAYBE_TRIGGER_WARNING (INTERNAL, nr, parentKey, message);
MAYBE_TRIGGER_WARNING (INTERFACE, nr, parentKey, message);
MAYBE_TRIGGER_WARNING (PLUGIN_MISBEHAVIOR, nr, parentKey, message);
MAYBE_TRIGGER_WARNING (CONFLICTING_STATE, nr, parentKey, message);
MAYBE_TRIGGER_WARNING (VALIDATION_SYNTACTIC, nr, parentKey, message);
MAYBE_TRIGGER_WARNING (VALIDATION_SEMANTIC, nr, parentKey, message);
ELEKTRA_ADD_INTERNAL_WARNINGF (parentKey, "Unkown warning code %s", nr);
}

#define MAYBE_TRIGGER_ERROR(cname, code, pk, msg) \
do \
{ \
if (strcmp (code, ELEKTRA_ERROR_CODE_##cname) == 0) \
{ \
ELEKTRA_SET_##cname##_ERROR (pk, msg); \
return; \
} \
} while (0)

void elektraTriggerError (const char * nr, Key * parentKey, const char * message)
{
if (strcmp (nr, ELEKTRA_ERROR_RESOURCE) == 0)
{
ELEKTRA_SET_RESOURCE_ERROR (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_ERROR_OUT_OF_MEMORY) == 0)
// OOM error is different, so check that one first
if (strcmp (nr, ELEKTRA_ERROR_CODE_OUT_OF_MEMORY) == 0)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
return;
}
if (strcmp (nr, ELEKTRA_ERROR_INSTALLATION) == 0)
{
ELEKTRA_SET_INSTALLATION_ERROR (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_ERROR_INTERNAL) == 0)
{
ELEKTRA_SET_INTERNAL_ERROR (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_ERROR_INTERFACE) == 0)
{
ELEKTRA_SET_INTERFACE_ERROR (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_ERROR_PLUGIN_MISBEHAVIOR) == 0)
{
ELEKTRA_SET_PLUGIN_MISBEHAVIOR_ERROR (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_ERROR_CONFLICTING_STATE) == 0)
{
ELEKTRA_SET_CONFLICTING_STATE_ERROR (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_ERROR_VALIDATION_SYNTACTIC) == 0)
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (parentKey, message);
return;
}
if (strcmp (nr, ELEKTRA_ERROR_VALIDATION_SEMANTIC) == 0)
{
ELEKTRA_SET_VALIDATION_SEMANTIC_ERROR (parentKey, message);
return;
}

MAYBE_TRIGGER_ERROR (RESOURCE, nr, parentKey, message);
MAYBE_TRIGGER_ERROR (INSTALLATION, nr, parentKey, message);
MAYBE_TRIGGER_ERROR (INTERNAL, nr, parentKey, message);
MAYBE_TRIGGER_ERROR (INTERFACE, nr, parentKey, message);
MAYBE_TRIGGER_ERROR (PLUGIN_MISBEHAVIOR, nr, parentKey, message);
MAYBE_TRIGGER_ERROR (CONFLICTING_STATE, nr, parentKey, message);
MAYBE_TRIGGER_ERROR (VALIDATION_SYNTACTIC, nr, parentKey, message);
MAYBE_TRIGGER_ERROR (VALIDATION_SEMANTIC, nr, parentKey, message);
ELEKTRA_SET_INTERNAL_ERRORF (parentKey, "Unkown error code %s", nr);
}
21 changes: 0 additions & 21 deletions src/libs/elektra/symbols.map
Original file line number Diff line number Diff line change
Expand Up @@ -134,27 +134,6 @@ libelektra_1.0 {
ELEKTRA_WARNING_VALIDATION_SEMANTIC;
ELEKTRA_WARNING_VALIDATION_SYNTACTIC;

# export also names of errors and warnings
ELEKTRA_ERROR_CONFLICTING_STATE_NAME;
ELEKTRA_ERROR_INSTALLATION_NAME;
ELEKTRA_ERROR_INTERFACE_NAME;
ELEKTRA_ERROR_INTERNAL_NAME;
ELEKTRA_ERROR_OUT_OF_MEMORY_NAME;
ELEKTRA_ERROR_PLUGIN_MISBEHAVIOR_NAME;
ELEKTRA_ERROR_RESOURCE_NAME;
ELEKTRA_ERROR_VALIDATION_SEMANTIC_NAME;
ELEKTRA_ERROR_VALIDATION_SYNTACTIC_NAME;

ELEKTRA_WARNING_CONFLICTING_STATE_NAME;
ELEKTRA_WARNING_INSTALLATION_NAME;
ELEKTRA_WARNING_INTERFACE_NAME;
ELEKTRA_WARNING_INTERNAL_NAME;
ELEKTRA_WARNING_OUT_OF_MEMORY_NAME;
ELEKTRA_WARNING_PLUGIN_MISBEHAVIOR_NAME;
ELEKTRA_WARNING_RESOURCE_NAME;
ELEKTRA_WARNING_VALIDATION_SEMANTIC_NAME;
ELEKTRA_WARNING_VALIDATION_SYNTACTIC_NAME;

# kdb.h
elektraGOptsContract;
elektraGOptsContractFromStrings;
Expand Down
11 changes: 6 additions & 5 deletions src/libs/tools/include/errors/baseNotification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class BaseNotification
{
public:
/* constructor */
BaseNotification (std::string reason, std::string module, std::string file, std::string mountPoint, std::string configFile,
kdb::long_t line);
BaseNotification (std::string description, std::string reason, std::string module, std::string file, std::string mountPoint,
std::string configFile, kdb::long_t line);

/* setters */
void setData (const std::string & reason, const std::string & module, const std::string & file, const std::string & mountPoint,
const std::string & configFile, kdb::long_t line);
void setData (const std::string & description, const std::string & reason, const std::string & module, const std::string & file,
const std::string & mountPoint, const std::string & configFile, kdb::long_t line);

/* get references (for setting and getting member values) */
std::string & reason ();
Expand All @@ -35,6 +35,7 @@ class BaseNotification
std::string & mountPoint ();
std::string & configFile ();
kdb::long_t & line ();
const std::string & description () const;
const std::string & reason () const;
const std::string & module () const;
const std::string & file () const;
Expand All @@ -44,7 +45,6 @@ class BaseNotification

/* fixed values per Class, taken from C-makro definitions in /src/include/kdberrors.h */
virtual std::string code () const = 0;
virtual std::string description () const = 0;

/* string representation */
friend std::ostream & operator<< (std::ostream & outputStream, const BaseNotification & eb);
Expand Down Expand Up @@ -93,6 +93,7 @@ class BaseNotification
virtual std::ostream & toString (std::ostream & outputStream) const;

private:
std::string m_description;
std::string m_reason;
std::string m_module;
std::string m_file;
Expand Down
8 changes: 3 additions & 5 deletions src/libs/tools/include/errors/errorFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class ErrorFactory

/* takes one of the ELEKTRA_ERROR_* constants (e.g. ELEKTRA_ERROR_OUT_OF_MEMORY)
* from /src/include/kdberrors.h as a parameter */
static Error * create (const std::string & type, const std::string & reason, const std::string & module, const std::string & file,
const std::string & mountPoint, const std::string & configFile, kdb::long_t line);
static Error * create (const std::string & type, const std::string & description, const std::string & reason,
const std::string & module, const std::string & file, const std::string & mountPoint,
const std::string & configFile, kdb::long_t line);

/**
* @brief Create an error from a given key
Expand All @@ -37,9 +38,6 @@ class ErrorFactory
* @return the error with warnings
*/
static Error * fromKey (kdb::Key key);

/* checks if a code and description fit together */
static bool checkErrorCodeDesc (const std::string & code, const std::string & description);
};

} // namespace errors
Expand Down
Loading

0 comments on commit e5ddb14

Please sign in to comment.