iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
error_forwarding.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 by Apex.AI Inc. All rights reserved.
2// Copyright (c) 2025 Contributors to the Eclipse Foundation
3//
4// See the NOTICE file(s) distributed with this work for additional
5// information regarding copyright ownership.
6//
7// This program and the accompanying materials are made available under the
8// terms of the Apache Software License 2.0 which is available at
9// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
10// which is available at https://opensource.org/licenses/MIT.
11//
12// SPDX-License-Identifier: Apache-2.0 OR MIT
13
14#ifndef IOX2_BB_REPORTING_ERROR_REPORTING_ERROR_FORWARDING_HPP
15#define IOX2_BB_REPORTING_ERROR_REPORTING_ERROR_FORWARDING_HPP
16
19
20// to establish connection to the custom implementation
22
23#include <type_traits>
24#include <utility>
25
26namespace iox2 {
27namespace legacy {
28namespace er {
29// This is lightweight and only exists to hide some complexity that would otherwise be part of the
30// macro API.
31
36template <typename Message>
37[[noreturn]] inline void forwardPanic(const bb::detail::SourceLocation& location, Message&& msg) {
38 panic(location, std::forward<Message>(msg));
39 abort();
40}
41
42namespace detail {
43// workaround for gcc 8 bug
44// see also https://github.com/eclipse-iceoryx/iceoryx2/issues/855
45template <typename T1, typename T2, typename Message>
46[[noreturn]] constexpr inline void unreachable_wrapped(const bb::detail::SourceLocation& location, Message&& msg) {
47 if (std::is_same<T1, T2>::value) {
48 forwardPanic(location, std::forward<Message>(msg));
49 }
50}
51} // namespace detail
52
58template <typename Error, typename Kind>
60 Kind&& kind,
61 const bb::detail::SourceLocation& location,
62 const char* stringifiedCondition) {
63 using K = typename std::remove_const<typename std::remove_reference<Kind>::type>::type;
64 static_assert(IsFatal<K>::value, "Must forward a fatal error!");
65
66 report(location, std::forward<Kind>(kind), std::forward<Error>(error), stringifiedCondition);
67 panic(location);
68 abort();
69}
70
76template <typename Error, typename Kind>
78 Kind&& kind,
79 const bb::detail::SourceLocation& location,
80 const char* stringifiedCondition) {
81 using K = typename std::remove_const<typename std::remove_reference<Kind>::type>::type;
82 static_assert(!IsFatal<K>::value, "Must forward a non-fatal error!");
83
84 report(location, std::forward<Kind>(kind), std::forward<Error>(error), stringifiedCondition);
85}
86
93template <typename Error, typename Kind, typename Message>
94// NOLINTNEXTLINE(readability-function-size) Not used directly but via a macro which hides the number of parameter away
96 Kind&& kind,
97 const bb::detail::SourceLocation& location,
98 const char* stringifiedCondition,
99 Message&& msg) {
100 using K = typename std::remove_const<typename std::remove_reference<Kind>::type>::type;
101 static_assert(IsFatal<K>::value, "Must forward a fatal error!");
102
103 report(location,
104 std::forward<Kind>(kind),
105 std::forward<Error>(error),
107 std::forward<Message>(msg));
108 panic(location);
109 abort();
110}
111
112} // namespace er
113} // namespace legacy
114} // namespace iox2
115
116#endif // IOX2_BB_REPORTING_ERROR_REPORTING_ERROR_FORWARDING_HPP
constexpr void unreachable_wrapped(const bb::detail::SourceLocation &location, Message &&msg)
void forwardNonFatalError(Error &&error, Kind &&kind, const bb::detail::SourceLocation &location, const char *stringifiedCondition)
Forwards a non-fatal error.
void forwardPanic(const bb::detail::SourceLocation &location, Message &&msg)
Forwards that a panic state was encountered and does not return.
void forwardFatalError(Error &&error, Kind &&kind, const bb::detail::SourceLocation &location, const char *stringifiedCondition)
Forwards a fatal error and does not return.
void report(const bb::detail::SourceLocation &location, Kind, const Error &error, const char *stringifiedCondition)
constexpr bool always_false_v
Helper value to bind a static_assert to a type.
helper struct to create an expected which is signalling an error more easily