]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson: rework discarding errors in errorator.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 13 Sep 2019 22:42:53 +0000 (00:42 +0200)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 20 Nov 2019 19:37:40 +0000 (20:37 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/crimson/common/errorator.h

index faa714afc94b66d311717d0fdb9ca48d57d1f01b..39092e5966a6fa8bf6872c733825904c3db7e6e6 100644 (file)
@@ -54,6 +54,10 @@ public:
   exception(const exception&) = default;
 };
 
+namespace _impl {
+  template <class T> struct always_false : std::false_type {};
+};
+
 template <class ErrorVisitorT, class FuturatorT>
 class maybe_handle_error_t {
   const std::type_info& type_info;
@@ -95,10 +99,17 @@ public:
       // call `report_failed_future()` during `operator=()`.
       std::move(result).get_exception();
 
-      constexpr bool explicitly_discarded = std::is_invocable_r<
-        struct ignore_marker_t&&, ErrorVisitorT, ErrorT>::value;
-      if constexpr (!explicitly_discarded) {
+      using return_t = std::invoke_result_t<ErrorVisitorT, ErrorT>;
+      if constexpr (std::is_assignable_v<decltype(result), return_t>) {
         result = std::forward<ErrorVisitorT>(errfunc)(ErrorT::instance);
+      } else if constexpr (std::is_same_v<return_t, void>) {
+        // void denotes explicit discarding
+        // execute for the sake a side effects. Typically this boils down
+        // to throwing an exception by the handler.
+        std::forward<ErrorVisitorT>(errfunc)(ErrorT::instance);
+      } else {
+        static_assert(_impl::always_false<return_t>::value,
+                      "return of Error Visitor is not assignable to future");
       }
     }
   }
@@ -108,10 +119,6 @@ public:
   }
 };
 
-namespace _impl {
-  template <class T> struct always_false : std::false_type {};
-};
-
 template <class FuncHead, class... FuncTail>
 static constexpr auto composer(FuncHead&& head, FuncTail&&... tail) {
   return [
@@ -356,7 +363,6 @@ struct errorator {
       static_assert((... || std::is_same_v<AllowedErrors,
                                            std::decay_t<ErrorT>>),
                     "discarding disallowed ErrorT");
-      return ignore_marker_t{};
     }
   };