iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
hoofs_error_reporting.hpp
Go to the documentation of this file.
1// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved.
2// Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved.
3// Copyright (c) 2024 by ekxide IO GmbH. All rights reserved.
4// Copyright (c) 2025 Contributors to the Eclipse Foundation
5//
6// See the NOTICE file(s) distributed with this work for additional
7// information regarding copyright ownership.
8//
9// This program and the accompanying materials are made available under the
10// terms of the Apache Software License 2.0 which is available at
11// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
12// which is available at https://opensource.org/licenses/MIT.
13//
14// SPDX-License-Identifier: Apache-2.0 OR MIT
15
16#ifndef IOX2_BB_ERROR_HANDLING_ERROR_HANDLING_HPP
17#define IOX2_BB_ERROR_HANDLING_ERROR_HANDLING_HPP
18
19// Each module (= some unit with its own errors) must provide the following.
20
21// 1. Define the errors of the module -> see below
22
23// 2. Include the custom reporting implementation
25
26// 3. Include the error reporting macro API
28
29// additional includes
32
33namespace iox2 {
34namespace legacy {
35// clang-format off
36
37// NOLINTJUSTIFICATION This macro is usee to define an enum and an array with corresponding enum tag names
38// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
39#define IOX2_BB_ERRORS(error) \
40 error(DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER) // keep this always at the end of the error list
41
42// clang-format on
43
44// DO NOT TOUCH THE ENUM, you can doodle around with the lines above!!!
45
46// NOLINTNEXTLINE(performance-enum-size) the type is required for error handling
50
51static const char* asStringLiteral(const HoofsError error) {
52 // NOLINTJUSTIFICATION Use to map enum tag names to strings
53 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays)
55
56 auto end =
57 static_cast<std::underlying_type<HoofsError>::type>(HoofsError::DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER);
58 auto index = static_cast<std::underlying_type<HoofsError>::type>(error);
59 if (index >= end) {
60 return "Unknown Error Code!";
61 }
62 // NOLINTJUSTIFICATION Bounds are checked and access is safe
63 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index)
64 return BB_ERROR_NAMES[index];
65}
66
68 public:
70 : m_code(static_cast<iox2::legacy::er::ErrorCode::type>(code)) {
71 }
72
74 return MODULE_ID;
75 }
76
78 return m_code;
79 }
80
81 const char* name() const {
82 return asStringLiteral(static_cast<HoofsError>(m_code.value));
83 }
84
85 static const char* moduleName() {
86 return "iceoryx2-bb-cxx";
87 }
88
90
91 protected:
93};
94
95namespace er {
96
98 return HoofsErrorType(code);
99}
100
104
105} // namespace er
106
107} // namespace legacy
108} // namespace iox2
109
110#endif // IOX2_BB_ERROR_HANDLING_ERROR_HANDLING_HPP
iox2::legacy::er::ErrorCode code() const
static constexpr iox2::legacy::er::ModuleId MODULE_ID
static constexpr iox2::legacy::er::ModuleId module()
iox2::legacy::er::ErrorCode m_code
#define IOX2_BB_ERRORS(error)
HoofsErrorType toError(HoofsError code)
ModuleId toModule(HoofsError)
constexpr bool always_false_v
Helper value to bind a static_assert to a type.
static const char * asStringLiteral(const HoofsError error)
detail::err< T > error
Definition expected.hpp:32
helper struct to create an expected which is signalling an error more easily
static constexpr type IOX2_BB
Definition types.hpp:54
#define IOX2_CREATE_ERROR_STRING(name)
Definition types.hpp:114