Skip to content

Commit

Permalink
Merge pull request #2686 from Piankero/error_codes_implementation
Browse files Browse the repository at this point in the history
Error codes implementation
  • Loading branch information
markus2330 committed Jun 27, 2019
2 parents 2e38a6c + b3c46c9 commit 76f2b79
Show file tree
Hide file tree
Showing 150 changed files with 1,880 additions and 3,459 deletions.
44 changes: 35 additions & 9 deletions cmake/Modules/LibAddLib.cmake
@@ -1,26 +1,52 @@
function (add_lib name)
cmake_parse_arguments (ARG
"CPP" # optional keywords
"" # one value keywords
"SOURCES;LINK_LIBRARIES;LINK_ELEKTRA" # multi value keywords
${ARGN})
function (set_additional_compile_definitions shortname)
if (NOT "${ARG_COMPILE_DEFINITIONS}" MATCHES "ELEKTRA_MODULE_NAME")
list (APPEND ADDITIONAL_COMPILE_DEFINITIONS_PARTS
"ELEKTRA_MODULE_NAME=${shortname}")
endif ()

set (ADDITIONAL_COMPILE_DEFINITIONS "${ADDITIONAL_COMPILE_DEFINITIONS_PARTS}" PARENT_SCOPE)
unset (ADDITIONAL_COMPILE_DEFINITIONS_PARTS)
endfunction (set_additional_compile_definitions)

function (add_lib name)
cmake_parse_arguments (
ARG
"CPP" # optional keywords
"" # one value keywords
"SOURCES;LINK_LIBRARIES;LINK_ELEKTRA;INCLUDE_DIRECTORIES;INCLUDE_SYSTEM_DIRECTORIES;COMPILE_DEFINITIONS" # multi value
# keywords
${ARGN})
add_headers (ARG_SOURCES)
if (ARG_CPP)
add_cppheaders (ARG_SOURCES)
endif (ARG_CPP)

add_library (elektra-${name}-objects OBJECT ${ARG_SOURCES})
add_dependencies (elektra-${name}-objects kdberrors_generated elektra_error_codes_generated)
target_include_directories (elektra-${name}-objects PUBLIC ${ARG_INCLUDE_DIRECTORIES})
target_include_directories (elektra-${name}-objects SYSTEM PUBLIC ${ARG_INCLUDE_SYSTEM_DIRECTORIES})

set_property (TARGET elektra-${name}-objects
PROPERTY POSITION_INDEPENDENT_CODE
ON)

set_additional_compile_definitions (${name})

set_property (TARGET elektra-${name}-objects
APPEND
PROPERTY COMPILE_DEFINITIONS
"${ARG_COMPILE_DEFINITIONS};${ADDITIONAL_COMPILE_DEFINITIONS}")

if (BUILD_SHARED)
add_library (elektra-${name} SHARED ${ARG_SOURCES})
add_dependencies (elektra-${name} kdberrors_generated elektra_error_codes_generated ${ARG_LINK_ELEKTRA})
add_library (elektra-${name} SHARED $<TARGET_OBJECTS:elektra-${name}-objects>)

target_link_libraries (elektra-${name} elektra-core ${ARG_LINK_ELEKTRA})
endif (BUILD_SHARED)

set_property (GLOBAL
APPEND
PROPERTY "elektra-full_SRCS"
${ARG_SOURCES})
"$<TARGET_OBJECTS:elektra-${name}-objects>")

set_property (GLOBAL
APPEND
Expand Down
2 changes: 0 additions & 2 deletions cmake/Modules/LibAddMacros.cmake
Expand Up @@ -214,9 +214,7 @@ macro (add_headers HDR_FILES)
${SRC_HDR_FILES})

set_source_files_properties (${BINARY_INCLUDE_DIR}/kdberrors.h PROPERTIES GENERATED ON SKIP_AUTOMOC ON)
set_source_files_properties (${BINARY_INCLUDE_DIR}/elektra/errorcodes.h PROPERTIES GENERATED ON SKIP_AUTOMOC ON)
set_source_files_properties (${BINARY_INCLUDE_DIR}/elektra/errors.h PROPERTIES GENERATED ON SKIP_AUTOMOC ON)
set_source_files_properties (${BINARY_INCLUDE_DIR}/elektra/errorsprivate.h PROPERTIES GENERATED ON SKIP_AUTOMOC ON)
list (APPEND ${HDR_FILES}
"${BINARY_INCLUDE_DIR}/kdberrors.h")
endmacro (add_headers)
Expand Down
5 changes: 5 additions & 0 deletions cmake/Modules/LibAddPlugin.cmake
Expand Up @@ -28,6 +28,11 @@ function (set_additional_compile_definitions shortname)
"ELEKTRA_PLUGIN_NAME_C=${shortname}")
endif ()

if (NOT "${ARG_COMPILE_DEFINITIONS}" MATCHES "ELEKTRA_MODULE_NAME")
list (APPEND ADDITIONAL_COMPILE_DEFINITIONS_PARTS
"ELEKTRA_MODULE_NAME=${shortname}")
endif ()

set (ADDITIONAL_COMPILE_DEFINITIONS "${ADDITIONAL_COMPILE_DEFINITIONS_PARTS}" PARENT_SCOPE)
unset (ADDITIONAL_COMPILE_DEFINITIONS_PARTS)
endfunction (set_additional_compile_definitions)
Expand Down
6 changes: 5 additions & 1 deletion doc/news/_preparation_next_release.md
Expand Up @@ -70,7 +70,11 @@ IMPORTANT: `kdbEnsure` only works, if the `list` plugin is mounted in all approp
Note: `kdbEnsure` right now ignores the `infos/recommends` and `infos/needs` metadata of plugins, so you have to explicitly take care of
dependencies. _(Klemens Böswirth)_

### <<HIGHLIGHT2>>
### Error Code Concept

With this release, we changed our messy error code system into a more structured and clean way. Similar to [SQLStates](https://www.ibm.com/support/knowledgecenter/en/SSGU8G_12.1.0/com.ibm.sqls.doc/ids_sqs_0809.htm) we changed to structure of our error codes and migrated them. Have a look into
the new [codes](../../src/error/specification). This allows us to easily extend the specification without breaking existing
codes and to avoid risking duplicated errors as we had before. _(Michael Zronek)_

## Plugins

Expand Down
6 changes: 3 additions & 3 deletions doc/tutorials/plugins.md
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(74, parentKey, keyString(parentKey));
ELEKTRA_SET_RESOURCE_ERROR(parentKey, keyString(parentKey));
}
for (/* each key */)
{
Expand Down Expand Up @@ -404,8 +404,8 @@ int elektraLineCheckConfig (Key * errorKey, KeySet * conf)
const char * value = keyString (cur);
if (strlen (value) > 3)
{
ELEKTRA_SET_ERRORF (ELEKTRA_ERROR_VALUE_LENGTH, errorKey,
"value %s is more than 3 characters long",
ELEKTRA_SET_VALIDATION_SYNTACTIC_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
12 changes: 6 additions & 6 deletions doc/tutorials/validation.md
Expand Up @@ -45,8 +45,8 @@ The most direct way to validate keys is
sudo kdb mount validation.dump user/tests/together dump validation
kdb vset user/tests/together/test 123 "[1-9][0-9]*" "Not a number"
kdb set user/tests/together/test abc
# STDERR: Sorry, module validator issued the error.*
# ERROR: 42
# STDERR: Sorry, module validation issued the error.*
# ERROR:C03100
# RET:5
```

Expand Down Expand Up @@ -264,8 +264,8 @@ you can run into [this](https://github.com/ElektraInitiative/libelektra/issues/2
```sh
kdb set /tests/tutorial/links/url "invalid url"
# STDOUT-REGEX: Using name (user|system)/tests/tutorial/links/url
# STDERR: .*key value failed to validate.*not a valid URL.*
# ERROR: 42
# STDERR: .*Validation Syntactic.*not a valid URL.*
# ERROR: C03100
# RET: 5
```

Expand Down Expand Up @@ -298,13 +298,13 @@ There are many ways to do so directly supported by [the spec plugin](/src/plugin
Another way is to trigger errors with the [error plugin](/src/plugins/error):

```sh
kdb setmeta /tests/tutorial/spec/should_not_be_here trigger/error 10
kdb setmeta /tests/tutorial/spec/should_not_be_here trigger/error C03200
#> Using keyname spec/tests/tutorial/spec/should_not_be_here
kdb spec-mount /tests/tutorial
kdb set /tests/tutorial/spec/should_not_be_here abc
# STDOUT-REGEX: Using name (user|system)/tests/tutorial/spec/should_not_be_here
# RET: 5
# ERROR:10
# ERROR:C03200
kdb get /tests/tutorial/spec/should_not_be_here
# RET: 11
# STDERR: Did not find key '/tests/tutorial/spec/should_not_be_here'
Expand Down
22 changes: 11 additions & 11 deletions examples/CMakeLists.txt
Expand Up @@ -57,7 +57,7 @@ if (FOUND_NAME GREATER -1)

target_link_elektra (${EXAMPLE} elektra-kdb elektra-notification)

# TODO resolve issues.libelektra.org/2007
# TODO resolve https://issues.libelektra.org/2007
check_binding_was_added ("io_uv" IS_INCLUDED)
if (IS_INCLUDED)

Expand All @@ -68,7 +68,7 @@ if (FOUND_NAME GREATER -1)
set (SOURCES ${SRC_FILES} ${HDR_FILES})
if (BUILD_FULL OR BUILD_STATIC)
list (APPEND SOURCES
$<TARGET_OBJECTS:OBJ_elektra-io-uv>) # add sources for elektra-io-uv for static and full builds
$<TARGET_OBJECTS:elektra-io-uv-objects>) # add sources for elektra-io-uv for static and full builds
endif ()

add_executable (${EXAMPLE} ${SOURCES})
Expand All @@ -85,6 +85,7 @@ if (FOUND_NAME GREATER -1)
else ()
target_compile_definitions (${EXAMPLE} PRIVATE "HAVE_LIBUV1")
endif ()
target_include_directories (${EXAMPLE} PRIVATE ${libuv_INCLUDE_DIRS})

endif ()

Expand All @@ -96,15 +97,14 @@ if (FOUND_NAME GREATER -1)

set (SRC_FILES notificationReload.c)
set (SOURCES ${SRC_FILES} ${HDR_FILES})
if (BUILD_FULL OR BUILD_STATIC)
# Work around missing header errors that occurs if only `BUILD_FULL`, but not `BUILD_SHARED` is enabled.
find_package (GLib QUIET)
find_package (libuv QUIET)
include_directories (${GLib_INCLUDE_DIRS} ${libuv_INCLUDE_DIRS})

list (APPEND SOURCES
$<TARGET_OBJECTS:OBJ_elektra-io-glib>) # add sources for elektra-io-uv for static and full builds
endif ()
# if (BUILD_FULL OR BUILD_STATIC) Work around missing header errors that occurs if only `BUILD_FULL`, but not `BUILD_SHARED`
# is enabled.
find_package (GLib QUIET)
find_package (libuv QUIET)
include_directories (${GLib_INCLUDE_DIRS} ${libuv_INCLUDE_DIRS})

list (APPEND SOURCES
$<TARGET_OBJECTS:elektra-io-glib-objects>) # add sources for elektra-io-uv for static and full builds endif ()

add_executable (${EXAMPLE} ${SOURCES})
add_dependencies (${EXAMPLE} kdberrors_generated elektra_error_codes_generated)
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/cpp/include/kdbplugin.hpp
Expand Up @@ -76,7 +76,7 @@ class Delegator
catch (const char * msg)
{
#ifdef KDBERRORS_H
ELEKTRA_ADD_WARNING (69, errorKey, msg);
ELEKTRA_ADD_PLUGIN_MISBEHAVIOR_WARNINGF (errorKey, "Could not create C++ plugin. Reason: %s", msg);
#endif
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/haskell/src/Elektra/Errors.chs
Expand Up @@ -15,5 +15,5 @@ module Elektra.Errors (

{#context lib="libelektra" #}

{#fun unsafe hsElektraTriggerError as triggerError {`Int', `Key', `String'} -> `()' #}
{#fun unsafe hsElektraTriggerWarnings as triggerWarnings {`Int', `Key', `String'} -> `()' #}
{#fun unsafe hsElektraTriggerError as triggerError {`String', `Key', `String'} -> `()' #}
{#fun unsafe hsElektraTriggerWarnings as triggerWarnings {`String', `Key', `String'} -> `()' #}
4 changes: 2 additions & 2 deletions src/bindings/haskell/src/c/hskdberrors.c
Expand Up @@ -8,12 +8,12 @@
#include <hskdberrors.h>
#include <kdberrors.h>

void hsElektraTriggerError (int nr, Key * parentKey, const char * message)
void hsElektraTriggerError (const char * nr, Key * parentKey, const char * message)
{
elektraTriggerError (nr, parentKey, message);
}

void hsElektraTriggerWarnings (int nr, Key * parentKey, const char * message)
void hsElektraTriggerWarnings (const char * nr, Key * parentKey, const char * message)
{
elektraTriggerWarnings (nr, parentKey, message);
}
4 changes: 2 additions & 2 deletions src/bindings/haskell/src/include/hskdberrors.h
Expand Up @@ -10,7 +10,7 @@

#include <kdb.h>

void hsElektraTriggerError (int nr, Key * parentKey, const char * message);
void hsElektraTriggerWarnings (int nr, Key * parentKey, const char * message);
void hsElektraTriggerError (const char * nr, Key * parentKey, const char * message);
void hsElektraTriggerWarnings (const char * nr, Key * parentKey, const char * message);

#endif
23 changes: 10 additions & 13 deletions src/bindings/io/ev/CMakeLists.txt
Expand Up @@ -15,18 +15,15 @@ else () # Build library

set (IO_VARIANT_LIBRARY elektra-io-${BINDING_VARIANT})

# create object library so that executables can use $<TARGET_OBJECTS:OBJ_${IO_VARIANT_LIBRARY}>
add_library (OBJ_${IO_VARIANT_LIBRARY} OBJECT ${SOURCES})
target_include_directories (OBJ_${IO_VARIANT_LIBRARY} SYSTEM PUBLIC ${LIBEV_INCLUDE_DIRS})

add_lib (io-${BINDING_VARIANT} SOURCES ${SOURCES} LINK_ELEKTRA elektra-io LINK_LIBRARIES ${LIBEV_LIBRARIES})

if (BUILD_FULL OR BUILD_STATIC)
add_includes ("elektra-full" ${LIBEV_INCLUDE_DIRS})
endif ()
if (BUILD_SHARED)
target_include_directories (${IO_VARIANT_LIBRARY} SYSTEM PUBLIC ${LIBEV_INCLUDE_DIRS})
endif ()
add_lib (io-${BINDING_VARIANT}
SOURCES
${SOURCES}
LINK_ELEKTRA
elektra-io
LINK_LIBRARIES
${LIBEV_LIBRARIES}
INCLUDE_SYSTEM_DIRECTORIES
${LIBEV_INCLUDE_DIRS})

configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/${IO_VARIANT_LIBRARY}.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${IO_VARIANT_LIBRARY}.pc"
Expand All @@ -48,7 +45,7 @@ else () # Build library

if (BUILD_FULL OR BUILD_STATIC) # add sources for elektra-io-ev for static and full builds
list (APPEND TEST_SOURCES
$<TARGET_OBJECTS:OBJ_${IO_VARIANT_LIBRARY}>)
$<TARGET_OBJECTS:${IO_VARIANT_LIBRARY}-objects>)
endif ()

add_executable (${testexename} ${TEST_SOURCES})
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/io/ev/example/CMakeLists.txt
Expand Up @@ -10,7 +10,7 @@ set (SOURCES ${SRC_FILES} ${HDR_FILES} ${ELEKTRA_HEADERS})

if (BUILD_FULL OR BUILD_STATIC) # add sources for elektra-io-ev for static and full builds
list (APPEND SOURCES
$<TARGET_OBJECTS:OBJ_elektra-io-ev>)
$<TARGET_OBJECTS:elektra-io-ev-objects>)
endif ()

# Build test
Expand Down
23 changes: 10 additions & 13 deletions src/bindings/io/glib/CMakeLists.txt
Expand Up @@ -20,18 +20,15 @@ else ()

set (IO_VARIANT_LIBRARY elektra-io-${BINDING_VARIANT})

# create object library so that executables can use $<TARGET_OBJECTS:OBJ_${IO_VARIANT_LIBRARY}>
add_library (OBJ_${IO_VARIANT_LIBRARY} OBJECT ${SOURCES})
target_include_directories (OBJ_${IO_VARIANT_LIBRARY} SYSTEM PUBLIC ${GLib_INCLUDE_DIRS})

add_lib (io-${BINDING_VARIANT} SOURCES ${SOURCES} LINK_ELEKTRA elektra-io LINK_LIBRARIES ${GLib_LIBRARY})

if (BUILD_FULL OR BUILD_STATIC)
add_includes ("elektra-full" ${GLib_INCLUDE_DIRS})
endif ()
if (BUILD_SHARED)
target_include_directories (${IO_VARIANT_LIBRARY} SYSTEM PUBLIC ${GLib_INCLUDE_DIRS})
endif ()
add_lib (io-${BINDING_VARIANT}
SOURCES
${SOURCES}
LINK_ELEKTRA
elektra-io
LINK_LIBRARIES
${GLib_LIBRARY}
INCLUDE_SYSTEM_DIRECTORIES
${GLib_INCLUDE_DIRS})

configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/${IO_VARIANT_LIBRARY}.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${IO_VARIANT_LIBRARY}.pc"
Expand All @@ -53,7 +50,7 @@ else ()

if (BUILD_FULL OR BUILD_STATIC) # add sources for elektra-io-glib for static and full builds
list (APPEND TEST_SOURCES
$<TARGET_OBJECTS:OBJ_${IO_VARIANT_LIBRARY}>)
$<TARGET_OBJECTS:${IO_VARIANT_LIBRARY}-objects>)
endif ()

add_executable (${testexename} ${TEST_SOURCES})
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/io/glib/example/CMakeLists.txt
Expand Up @@ -10,7 +10,7 @@ set (SOURCES ${SRC_FILES} ${HDR_FILES} ${ELEKTRA_HEADERS})

if (BUILD_FULL OR BUILD_STATIC)
list (APPEND SOURCES
$<TARGET_OBJECTS:OBJ_elektra-io-glib>) # add sources for elektra-io-glib for static and full builds
$<TARGET_OBJECTS:elektra-io-glib-objects>) # add sources for elektra-io-glib for static and full builds
endif ()

# Build test
Expand Down
41 changes: 14 additions & 27 deletions src/bindings/io/uv/CMakeLists.txt
Expand Up @@ -21,36 +21,23 @@ else ()

set (IO_UV_LIBRARY elektra-io-${BINDING_VARIANT})

# create object library so that executables can use $<TARGET_OBJECTS:OBJ_${IO_UV_LIBRARY}>
add_library (OBJ_${IO_UV_LIBRARY} OBJECT ${SOURCES})
target_include_directories (OBJ_${IO_UV_LIBRARY} SYSTEM PUBLIC ${libuv_INCLUDE_DIRS})

if (libuv_VERSION VERSION_LESS "1.0")
target_compile_definitions (OBJ_${IO_UV_LIBRARY} PRIVATE "HAVE_LIBUV0")
set (HAVE_LIBUV_VERSION "HAVE_LIBUV0")
else ()
target_compile_definitions (OBJ_${IO_UV_LIBRARY} PRIVATE "HAVE_LIBUV1")
set (HAVE_LIBUV_VERSION "HAVE_LIBUV1")
endif ()

add_lib (io-${BINDING_VARIANT} SOURCES ${SOURCES} LINK_ELEKTRA elektra-io LINK_LIBRARIES ${libuv_LIBRARIES})

if (BUILD_FULL OR BUILD_STATIC)
add_includes ("elektra-full" ${libuv_INCLUDE_DIRS})

if (libuv_VERSION VERSION_LESS "1.0")
add_definitions ("-DHAVE_LIBUV0")
else ()
add_definitions ("-DHAVE_LIBUV1")
endif ()
endif ()
if (BUILD_SHARED)
target_include_directories (${IO_UV_LIBRARY} SYSTEM PUBLIC ${libuv_INCLUDE_DIRS})

if (libuv_VERSION VERSION_LESS "1.0")
target_compile_definitions (${IO_UV_LIBRARY} PRIVATE "HAVE_LIBUV0")
else ()
target_compile_definitions (${IO_UV_LIBRARY} PRIVATE "HAVE_LIBUV1")
endif ()
endif ()
add_lib (io-${BINDING_VARIANT}
SOURCES
${SOURCES}
LINK_ELEKTRA
elektra-io
LINK_LIBRARIES
${libuv_LIBRARIES}
INCLUDE_SYSTEM_DIRECTORIES
${libuv_INCLUDE_DIRS}
COMPILE_DEFINITIONS
${HAVE_LIBUV_VERSION})

configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/${IO_UV_LIBRARY}.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/${IO_UV_LIBRARY}.pc" @ONLY)

Expand All @@ -70,7 +57,7 @@ else ()

if (BUILD_FULL OR BUILD_STATIC)
list (APPEND TEST_SOURCES
$<TARGET_OBJECTS:OBJ_${IO_UV_LIBRARY}>) # add sources for elektra-io-uv for static and full builds
$<TARGET_OBJECTS:${IO_UV_LIBRARY}-objects>) # add sources for elektra-io-uv for static and full builds
endif ()

add_executable (${TESTEXENAME} ${TEST_SOURCES})
Expand Down

0 comments on commit 76f2b79

Please sign in to comment.