Skip to content

Commit

Permalink
Merge pull request #1170 from ApexAI/iox-#1099-separate-error-enums-f…
Browse files Browse the repository at this point in the history
…or-each-module

iox-#1099 Separate error enums for each module
  • Loading branch information
mossmaurice authored Mar 30, 2022
2 parents 1efa29a + 6a2c0d2 commit 262e631
Show file tree
Hide file tree
Showing 117 changed files with 1,190 additions and 1,071 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ Github [labels](https://github.com/eclipse-iceoryx/iceoryx/labels) are used to g
| Ruleset name | Github issue label | Priority |
|---|---|---|
| [Adaptive AUTOSAR](https://www.autosar.org/fileadmin/user_upload/standards/adaptive/17-03/AUTOSAR_RS_CPP14Guidelines.pdf) C++14 | AUTOSAR | :star::star::star: |
| [SEI CERT C++](https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88046682) 2016 Coding Standard | CERT | :star::star: |
| [SEI CERT C++](https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88046682)<!--NOLINT website temporarily unavailable--> 2016 Coding Standard | CERT | :star::star: |
| [MISRA](https://www.misra.org.uk/) C++ 2008 | MISRA | :star: |

If one of the rules is not followed, a rationale is added in the following manner:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ In general unix platforms should work with iceoryx but we only test FreeBSD on o
| [RTA-VRTE](https://www.etas.com/en/products/rta-vrte.php) | [AUTOSAR Adaptive Platform](https://www.autosar.org/standards/adaptive-platform/) software framework for vehicle computer from [ETAS GmbH](https://www.etas.com) |
| [Cyclone DDS](https://github.com/eclipse-cyclonedds/cyclonedds) | Performant and robust open-source DDS implementation maintained by [ADLINK Technology Inc.](https://www.adlinktech.com/en/index.aspx) | <!--NOLINT ADlink seems to be sporadically unreachable-->
| [Apex.Middleware](https://www.apex.ai/apex-middleware) | Safe and certified middleware for autonomous mobility systems from [Apex.AI](https://www.apex.ai/) |
| [AVIN AP](https://www.avinsystems.com/products/autosar_ap_solutions/) | AUTOSAR Adaptive Platform Product from AVIN Systems |
| [AVIN AGNOSAR](https://www.avinsystems.com/products/agnosar_ap/) | AUTOSAR Adaptive Platform Product from AVIN Systems |

## Build and install

Expand Down
140 changes: 82 additions & 58 deletions doc/design/error-handling.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

**Refactoring:**

- Separate test specific code from `ErrorHandler` and templatize `setTemporaryErrorHandler()` [\#1099](https://github.com/eclipse-iceoryx/iceoryx/issues/1099)
- Separate module specific errors from `iceoryx_hoofs` [\#1099](https://github.com/eclipse-iceoryx/iceoryx/issues/1099)
- Move test specific code to `ErrorHandlerMock` and templatize `setTemporaryErrorHandler()`
- Create separate error enum for each module

**New API features:**

Expand Down
1 change: 1 addition & 0 deletions iceoryx_binding_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ add_library(${PROJECT_NAME}
source/cpp2c_subscriber.cpp
source/cpp2c_service_description_translation.cpp
source/c_service_discovery.cpp
source/error_handling.cpp
)
add_library(${PROJECT_NAMESPACE}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2020 - 2022 by Apex.AI Inc. 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// 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"

namespace iox
{
// clang-format off
#define C_BINDING_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) \
error(BINDING_C__SUBSCRIBER_OPTIONS_NOT_INITIALIZED) \
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_EVENT_VALUE) \
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_STATE_VALUE) \
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_EVENT_VALUE) \
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_STATE_VALUE) \
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)

// clang-format on

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

enum class CBindingError : uint32_t
{
NO_ERROR = C_BINDING_MODULE_IDENTIFIER << ERROR_ENUM_OFFSET_IN_BITS,
C_BINDING_ERRORS(CREATE_ICEORYX_ERROR_ENUM)
};

const char* asStringLiteral(const CBindingError error) noexcept;

} // namespace iox
#endif // IOX_BINDING_C_ERROR_HANDLING_ERROR_HANDLING_HPP
24 changes: 12 additions & 12 deletions iceoryx_binding_c/source/c2cpp_enum_translation.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_binding_c/internal/c2cpp_enum_translation.hpp"
#include "iceoryx_binding_c/error_handling/error_handling.hpp"
#include "iceoryx_binding_c/internal/c2cpp_binding.h"
#include "iceoryx_hoofs/error_handling/error_handling.hpp"

namespace c2cpp
{
Expand All @@ -30,8 +30,8 @@ iox::popo::ConsumerTooSlowPolicy consumerTooSlowPolicy(const ENUM iox_ConsumerTo
return iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA;
}

errorHandler(
iox::Error::kBINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY, nullptr, iox::ErrorLevel::MODERATE);
errorHandler(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY,
iox::ErrorLevel::MODERATE);
return iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA;
}

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

errorHandler(iox::Error::kBINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY, nullptr, iox::ErrorLevel::MODERATE);
errorHandler(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY, iox::ErrorLevel::MODERATE);
return iox::popo::QueueFullPolicy::DISCARD_OLDEST_DATA;
}

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

iox::LogFatal() << "invalid iox_SubscriberEvent value";
errorHandler(iox::Error::kBINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_EVENT_VALUE);
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_EVENT_VALUE);
return iox::popo::SubscriberEvent::DATA_RECEIVED;
}

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

iox::LogFatal() << "invalid iox_SubscriberState value";
errorHandler(iox::Error::kBINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_STATE_VALUE);
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_STATE_VALUE);
return iox::popo::SubscriberState::HAS_DATA;
}

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

iox::LogFatal() << "invalid iox_ClientEvent value";
errorHandler(iox::Error::kBINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_EVENT_VALUE);
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_EVENT_VALUE);
return iox::popo::ClientEvent::RESPONSE_RECEIVED;
}

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

iox::LogFatal() << "invalid iox_ClientState value";
errorHandler(iox::Error::kBINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_STATE_VALUE);
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_STATE_VALUE);
return iox::popo::ClientState::HAS_RESPONSE;
}

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

iox::LogFatal() << "invalid iox_ServerEvent value";
errorHandler(iox::Error::kBINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_EVENT_VALUE);
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_EVENT_VALUE);
return iox::popo::ServerEvent::REQUEST_RECEIVED;
}

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

iox::LogFatal() << "invalid iox_ServerState value";
errorHandler(iox::Error::kBINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_STATE_VALUE);
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_STATE_VALUE);
return iox::popo::ServerState::HAS_REQUEST;
}

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

iox::LogFatal() << "invalid iox_ServiceDiscoveryEvent value";
errorHandler(iox::Error::kBINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVICE_DISCOVERY_EVENT_VALUE);
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVICE_DISCOVERY_EVENT_VALUE);
return iox::runtime::ServiceDiscoveryEvent::SERVICE_REGISTRY_CHANGED;
}

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

iox::LogFatal() << "invalid iox_MessagingPattern value";
errorHandler(iox::Error::kBINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE);
errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE);
return iox::popo::MessagingPattern::PUB_SUB;
}

Expand Down
4 changes: 3 additions & 1 deletion iceoryx_binding_c/source/c_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_binding_c/error_handling/error_handling.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"
#include "iceoryx_binding_c/internal/cpp2c_service_description_translation.hpp"
#include "iceoryx_posh/internal/popo/ports/publisher_port_user.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"


using namespace iox;
using namespace iox::cxx;
using namespace iox::popo;
Expand Down Expand Up @@ -79,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
LogFatal() << "publisher options may not have been initialized with iox_pub_options_init";
errorHandler(Error::kBINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED);
errorHandler(CBindingError::BINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED);
}
publisherOptions.historyCapacity = options->historyCapacity;
if (options->nodeName != nullptr)
Expand Down
4 changes: 3 additions & 1 deletion iceoryx_binding_c/source/c_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


#include "iceoryx_binding_c/enums.h"
#include "iceoryx_binding_c/error_handling/error_handling.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 All @@ -27,6 +28,7 @@
#include "iceoryx_posh/mepoo/chunk_header.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"


using namespace iox;
using namespace iox::cxx;
using namespace iox::popo;
Expand Down Expand Up @@ -93,7 +95,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
LogFatal() << "subscriber options may not have been initialized with iox_sub_init";
errorHandler(Error::kBINDING_C__SUBSCRIBER_OPTIONS_NOT_INITIALIZED);
errorHandler(CBindingError::BINDING_C__SUBSCRIBER_OPTIONS_NOT_INITIALIZED);
}
subscriberOptions.queueCapacity = options->queueCapacity;
subscriberOptions.historyRequest = options->historyRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLING_INL
#define IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLING_INL

#include "iceoryx_hoofs/error_handling/error_handling.hpp"
#include "iceoryx_binding_c/error_handling/error_handling.hpp"

namespace iox
{
template <typename Error>
inline void errorHandler(const Error error,
const std::function<void()>& errorCallBack IOX_MAYBE_UNUSED,
const ErrorLevel level) noexcept
const char* C_BINDING_ERROR_NAMES[] = {C_BINDING_ERRORS(CREATE_ICEORYX_ERROR_STRING)};

const char* asStringLiteral(const CBindingError error) noexcept
{
ErrorHandler::handler(static_cast<typename std::underlying_type<Error>::type>(error), toString(error), level);
return C_BINDING_ERROR_NAMES[errorToStringIndex(error)];
}

} // namespace iox

#endif // IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLING_INL
Loading

0 comments on commit 262e631

Please sign in to comment.