Skip to content

Commit

Permalink
Merge pull request #2170 from elBoberido/iox-1032-port-to-new-error-h…
Browse files Browse the repository at this point in the history
…andling

iox-#1032 Port to new error handling
  • Loading branch information
elBoberido authored Feb 3, 2024
2 parents 549ec3e + 6e88fa5 commit 7135c57
Show file tree
Hide file tree
Showing 213 changed files with 1,435 additions and 2,356 deletions.
4 changes: 4 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ concurrency-*,
performance-*,
hicpp-*,
-cppcoreguidelines-avoid-do-while
-cppcoreguidelines-non-private-member-variables-in-classes,
-hicpp-named-parameter,
Expand Down Expand Up @@ -100,6 +101,9 @@ hicpp-*,
# * rule: readability-use-anyofallof
# justification: requires C++20 and std::ranges but we only use C++17
#
# * rule: cppcoreguidelines-avoid-do-while
# justification: there is nothing inherently wrong with do-while loops and there are valid use cases for them
#
# * rule: cppcoreguidelines-non-private-member-variables-in-classes
# justification: Sometimes it makes sense to have protected members to extend the base class.
# Even public members are useful in lightweight classes (effectively structs).
Expand Down
5 changes: 0 additions & 5 deletions .clang-tidy-diff-scans.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
./iceoryx_hoofs/include/iceoryx_hoofs/cxx/*
./iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/*
./iceoryx_hoofs/test/moduletests/test_cxx*
./iceoryx_hoofs/source/cxx/*

./iceoryx_hoofs/legacy/**/*

./iceoryx_hoofs/cli/**/*
Expand Down
24 changes: 23 additions & 1 deletion doc/aspice_swe3_4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,29 @@ generatedcode="@par Generated by:"]])
set(COMPONENTS iceoryx_hoofs iceoryx_posh iceoryx_binding_c
iceoryx_introspection iceoryx_component)
set(COMPONENT_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/buffer
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/cli
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/concurrent/buffer
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/concurrent/sync
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/container
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/design
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/filesystem
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/functional
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/legacy/include
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/memory
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/auth
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/desig
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/filesystem
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/ipc
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/sync
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/time
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/utility
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/vocabulary
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/primitives
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/reporting
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/time
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/utility
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/vocabulary
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_posh
${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_binding_c
${CMAKE_CURRENT_SOURCE_DIR}/../../tools/introspection
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_binding_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ iox_add_library(
PUBLIC_LIBS_APPLE stdc++ pthread
PRIVATE_LIBS iceoryx_posh::iceoryx_posh
FILES
source/binding_c_error_reporting.cpp
source/c_client.cpp
source/c_config.cpp
source/c_notification_info.cpp
Expand All @@ -72,7 +73,6 @@ iox_add_library(
source/cpp2c_subscriber.cpp
source/cpp2c_service_description_translation.cpp
source/c_service_discovery.cpp
source/error_handling.cpp
)

#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Mathias Kraus <[email protected]>. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,15 +15,28 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_BINDING_C_BINDING_ERROR_HANDLING_ERROR_HANDLING_HPP
#define IOX_BINDING_C_BINDING_ERROR_HANDLING_ERROR_HANDLING_HPP

#include "iceoryx_hoofs/error_handling/error_handler.hpp"
#ifndef IOX_BINDING_C_BINDING_C_ERROR_REPORTING_HPP
#define IOX_BINDING_C_BINDING_C_ERROR_REPORTING_HPP

// Each module (= some unit with its own errors) must provide the following.

// 1. Define the errors of the module -> see below

// 2. Include the custom reporting implementation
#include "iox/error_reporting/custom/error_reporting.hpp"

// 3. Include the error reporting macro API
#include "iox/error_reporting/macros.hpp"

// additional includes
#include "iox/error_reporting/types.hpp"

namespace iox
{

// clang-format off
#define C_BINDING_ERRORS(error) \
#define IOX_BINDING_C_ERRORS(error) \
error(BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY) \
error(BINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY) \
error(BINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED) \
Expand All @@ -34,19 +48,68 @@ namespace iox
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_EVENT_VALUE) \
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_STATE_VALUE) \
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVICE_DISCOVERY_EVENT_VALUE) \
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE)
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE) \
error(DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER) // keep this always at the end of the error list

// clang-format on

// DO NOT TOUCH THE ENUM, you can doodle around with the lines above!!!

enum class CBindingError : uint32_t
enum class CBindingError : iox::er::ErrorCode::type
{
NO_ERROR = C_BINDING_MODULE_IDENTIFIER << ERROR_ENUM_OFFSET_IN_BITS,
C_BINDING_ERRORS(CREATE_ICEORYX_ERROR_ENUM)
IOX_BINDING_C_ERRORS(IOX_CREATE_ERROR_ENUM)
};

const char* asStringLiteral(const CBindingError error) noexcept;

class CBindingErrorType
{
public:
explicit CBindingErrorType(CBindingError code)
: m_code(static_cast<iox::er::ErrorCode::type>(code))
{
}

static constexpr iox::er::ModuleId module()
{
return MODULE_ID;
}

iox::er::ErrorCode code() const
{
return m_code;
}

const char* name() const
{
return asStringLiteral(static_cast<CBindingError>(m_code.value));
}

static const char* moduleName()
{
return "iceoryx_binding_c";
}

static constexpr iox::er::ModuleId MODULE_ID{iox::er::ModuleId::BINDING_C};

protected:
iox::er::ErrorCode m_code;
};

namespace er
{

inline CBindingErrorType toError(CBindingError code)
{
return CBindingErrorType(code);
}

inline ModuleId toModule(CBindingError)
{
return CBindingErrorType::MODULE_ID;
}

} // namespace er
} // namespace iox
#endif // IOX_BINDING_C_ERROR_HANDLING_ERROR_HANDLING_HPP

#endif // IOX_BINDING_C_BINDING_C_ERROR_REPORTING_HPP
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Mathias Kraus <[email protected]>. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,14 +15,23 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_binding_c/error_handling/error_handling.hpp"
#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp"

namespace iox
{
const char* C_BINDING_ERROR_NAMES[] = {C_BINDING_ERRORS(CREATE_ICEORYX_ERROR_STRING)};
const char* BINDING_C_ERROR_NAMES[] = {IOX_BINDING_C_ERRORS(IOX_CREATE_ERROR_STRING)};

const char* asStringLiteral(const CBindingError error) noexcept
{
return C_BINDING_ERROR_NAMES[errorToStringIndex(error)];
auto end = static_cast<std::underlying_type<CBindingError>::type>(
CBindingError::DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER);
auto index = static_cast<std::underlying_type<CBindingError>::type>(error);
if (index >= end)
{
return "Unknown Error Code!";
}
// NOLINTJUSTIFICATION Bounds are checked and access is safe
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index)
return BINDING_C_ERROR_NAMES[index];
}
} // namespace iox
23 changes: 11 additions & 12 deletions iceoryx_binding_c/source/c2cpp_enum_translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp"
#include "iceoryx_binding_c/error_handling/error_handling.hpp"
#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp"
#include "iceoryx_binding_c/internal/c2cpp_binding.h"
#include "iox/logging.hpp"

Expand All @@ -31,8 +31,7 @@ iox::popo::ConsumerTooSlowPolicy consumerTooSlowPolicy(const ENUM iox_ConsumerTo
return iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA;
}

errorHandler(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY,
iox::ErrorLevel::MODERATE);
IOX_REPORT(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY, iox::er::RUNTIME_ERROR);
return iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA;
}

Expand All @@ -46,7 +45,7 @@ iox::popo::QueueFullPolicy queueFullPolicy(const ENUM iox_QueueFullPolicy policy
return iox::popo::QueueFullPolicy::DISCARD_OLDEST_DATA;
}

errorHandler(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY, iox::ErrorLevel::MODERATE);
IOX_REPORT(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY, iox::er::RUNTIME_ERROR);
return iox::popo::QueueFullPolicy::DISCARD_OLDEST_DATA;
}

Expand All @@ -59,7 +58,7 @@ iox::popo::SubscriberEvent subscriberEvent(const iox_SubscriberEvent value) noex
}

IOX_LOG(FATAL, "invalid iox_SubscriberEvent value");
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_EVENT_VALUE);
IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_EVENT_VALUE);
return iox::popo::SubscriberEvent::DATA_RECEIVED;
}

Expand All @@ -72,7 +71,7 @@ iox::popo::SubscriberState subscriberState(const iox_SubscriberState value) noex
}

IOX_LOG(FATAL, "invalid iox_SubscriberState value");
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_STATE_VALUE);
IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_STATE_VALUE);
return iox::popo::SubscriberState::HAS_DATA;
}

Expand All @@ -85,7 +84,7 @@ iox::popo::ClientEvent clientEvent(const iox_ClientEvent value) noexcept
}

IOX_LOG(FATAL, "invalid iox_ClientEvent value");
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_EVENT_VALUE);
IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_EVENT_VALUE);
return iox::popo::ClientEvent::RESPONSE_RECEIVED;
}

Expand All @@ -98,7 +97,7 @@ iox::popo::ClientState clientState(const iox_ClientState value) noexcept
}

IOX_LOG(FATAL, "invalid iox_ClientState value");
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_STATE_VALUE);
IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_STATE_VALUE);
return iox::popo::ClientState::HAS_RESPONSE;
}

Expand All @@ -111,7 +110,7 @@ iox::popo::ServerEvent serverEvent(const iox_ServerEvent value) noexcept
}

IOX_LOG(FATAL, "invalid iox_ServerEvent value");
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_EVENT_VALUE);
IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_EVENT_VALUE);
return iox::popo::ServerEvent::REQUEST_RECEIVED;
}

Expand All @@ -124,7 +123,7 @@ iox::popo::ServerState serverState(const iox_ServerState value) noexcept
}

IOX_LOG(FATAL, "invalid iox_ServerState value");
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_STATE_VALUE);
IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_STATE_VALUE);
return iox::popo::ServerState::HAS_REQUEST;
}

Expand All @@ -137,7 +136,7 @@ iox::runtime::ServiceDiscoveryEvent serviceDiscoveryEvent(const iox_ServiceDisco
}

IOX_LOG(FATAL, "invalid iox_ServiceDiscoveryEvent value");
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVICE_DISCOVERY_EVENT_VALUE);
IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVICE_DISCOVERY_EVENT_VALUE);
return iox::runtime::ServiceDiscoveryEvent::SERVICE_REGISTRY_CHANGED;
}

Expand All @@ -152,7 +151,7 @@ iox::popo::MessagingPattern messagingPattern(const iox_MessagingPattern value) n
}

IOX_LOG(FATAL, "invalid iox_MessagingPattern value");
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE);
IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE);
return iox::popo::MessagingPattern::PUB_SUB;
}

Expand Down
2 changes: 1 addition & 1 deletion iceoryx_binding_c/source/c_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_service_description_translation.hpp"
#include "iceoryx_hoofs/cxx/requires.hpp"
#include "iceoryx_posh/popo/untyped_client.hpp"
#include "iox/assertions.hpp"

using namespace iox;
using namespace iox::popo;
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_binding_c/source/c_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_binding_c/error_handling/error_handling.hpp"
#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp"
#include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_publisher.hpp"
Expand Down Expand Up @@ -81,7 +81,7 @@ iox_pub_t iox_pub_init(iox_pub_storage_t* self,
// note that they may have been initialized but the initCheck
// pattern overwritten afterwards, we cannot be sure but it is a misuse
IOX_LOG(FATAL, "publisher options may not have been initialized with iox_pub_options_init");
errorHandler(CBindingError::BINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED);
IOX_REPORT_FATAL(CBindingError::BINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED);
}
publisherOptions.historyCapacity = options->historyCapacity;
if (options->nodeName != nullptr)
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_binding_c/source/c_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/cxx/requires.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"
#include "iox/assertions.hpp"

using namespace iox;
using namespace iox::runtime;
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_binding_c/source/c_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_service_description_translation.hpp"
#include "iceoryx_hoofs/cxx/requires.hpp"
#include "iceoryx_posh/popo/untyped_server.hpp"
#include "iox/assertions.hpp"

using namespace iox;
using namespace iox::popo;
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_binding_c/source/c_service_discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_service_description_translation.hpp"
#include "iceoryx_hoofs/cxx/requires.hpp"
#include "iceoryx_posh/runtime/service_discovery.hpp"
#include "iox/assertions.hpp"
#include "iox/optional.hpp"

using namespace iox;
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_binding_c/source/c_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_binding_c/enums.h"
#include "iceoryx_binding_c/error_handling/error_handling.hpp"
#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp"
#include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_service_description_translation.hpp"
Expand Down Expand Up @@ -92,7 +92,7 @@ iox_sub_t iox_sub_init(iox_sub_storage_t* self,
// note that they may have been initialized but the initCheck
// pattern overwritten afterwards, we cannot be sure but it is a misuse
IOX_LOG(FATAL, "subscriber options may not have been initialized with iox_sub_init");
errorHandler(CBindingError::BINDING_C__SUBSCRIBER_OPTIONS_NOT_INITIALIZED);
IOX_REPORT_FATAL(CBindingError::BINDING_C__SUBSCRIBER_OPTIONS_NOT_INITIALIZED);
}
subscriberOptions.queueCapacity = options->queueCapacity;
subscriberOptions.historyRequest = options->historyRequest;
Expand Down
Loading

0 comments on commit 7135c57

Please sign in to comment.