Commit a8879903 authored by Dominik Charousset's avatar Dominik Charousset

Fix handling of inspector callback results

parent 58af91e1
...@@ -78,7 +78,18 @@ private: ...@@ -78,7 +78,18 @@ private:
template <class R, class T> template <class R, class T>
std::enable_if_t<meta::is_annotation_v<T>, bool> try_apply(R& result, T& x) { std::enable_if_t<meta::is_annotation_v<T>, bool> try_apply(R& result, T& x) {
if constexpr (meta::is_save_callback_v<T>) { if constexpr (meta::is_save_callback_v<T>) {
CAF_READ_INSPECTOR_TRY(x.fun()) using fun_result = decltype(x.fun());
if constexpr (std::is_same<fun_result, void>::value) {
x.fun();
} else {
if (auto err = x.fun()) {
if constexpr (std::is_assignable<T&, decltype(err)&&>::value)
result = std::move(err);
else
result = sec::save_callback_failed;
return false;
}
}
} }
return true; return true;
} }
......
...@@ -136,15 +136,21 @@ enum class sec : uint8_t { ...@@ -136,15 +136,21 @@ enum class sec : uint8_t {
malformed_basp_message, malformed_basp_message,
/// The middleman closed a connection because it failed to serialize or /// The middleman closed a connection because it failed to serialize or
/// deserialize a payload. /// deserialize a payload.
serializing_basp_payload_failed, serializing_basp_payload_failed = 50,
/// The middleman closed a connection to itself or an already connected node. /// The middleman closed a connection to itself or an already connected node.
redundant_connection, redundant_connection,
/// Resolving a path on a remote node failed. /// Resolving a path on a remote node failed.
remote_lookup_failed, remote_lookup_failed,
/// Disconnected from a BASP node after reaching the connection timeout.
connection_timeout,
/// Serialization failed because actor_system::tracing_context is null. /// Serialization failed because actor_system::tracing_context is null.
no_tracing_context, no_tracing_context,
/// No request produced a valid result. /// No request produced a valid result.
all_requests_failed, all_requests_failed,
/// Serializing failed because a save callback returned an error.
save_callback_failed,
/// Deserializing failed because a load callback returned an error.
load_callback_failed,
}; };
/// @relates sec /// @relates sec
...@@ -152,4 +158,4 @@ CAF_CORE_EXPORT std::string to_string(sec); ...@@ -152,4 +158,4 @@ CAF_CORE_EXPORT std::string to_string(sec);
} // namespace caf } // namespace caf
CAF_ERROR_CODE_ENUM(sec) CAF_ERROR_CODE_ENUM(caf::sec)
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "caf/detail/type_traits.hpp" #include "caf/detail/type_traits.hpp"
#include "caf/meta/annotation.hpp" #include "caf/meta/annotation.hpp"
#include "caf/meta/load_callback.hpp" #include "caf/meta/load_callback.hpp"
#include "caf/sec.hpp"
#include "caf/unifyn.hpp" #include "caf/unifyn.hpp"
#define CAF_WRITE_INSPECTOR_TRY(statement) \ #define CAF_WRITE_INSPECTOR_TRY(statement) \
...@@ -81,7 +82,18 @@ private: ...@@ -81,7 +82,18 @@ private:
template <class R, class T> template <class R, class T>
std::enable_if_t<meta::is_annotation_v<T>, bool> try_apply(R& result, T& x) { std::enable_if_t<meta::is_annotation_v<T>, bool> try_apply(R& result, T& x) {
if constexpr (meta::is_load_callback_v<T>) { if constexpr (meta::is_load_callback_v<T>) {
CAF_WRITE_INSPECTOR_TRY(x.fun()) using fun_result = decltype(x.fun());
if constexpr (std::is_same<fun_result, void>::value) {
x.fun();
} else {
if (auto err = x.fun()) {
if constexpr (std::is_assignable<T&, decltype(err)&&>::value)
result = std::move(err);
else
result = sec::load_callback_failed;
return false;
}
}
} }
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment