]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/common: stateful_error_t allows for void-taking handlers.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 19 Mar 2021 08:31:33 +0000 (08:31 +0000)
committerKefu Chai <kchai@redhat.com>
Fri, 2 Apr 2021 07:29:58 +0000 (15:29 +0800)
Before this commit there was an inconsistencty between
`unthrowable_wrapper::handle()` and `stateful_error_t::handle()`
in the regard of parameters the provided handler had to accept.
The former was fine with void-taking handlers while the latter
was not.

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/crimson/common/errorator.h

index 7fd053740841ba5335040ed2189ba79ed89b9c7e..058f9fe8c64b861c08c96ee804802b67e5a98152 100644 (file)
@@ -190,14 +190,17 @@ struct stateful_error_t : error_t<stateful_error_t<ErrorT>> {
 
   template<class Func>
   static auto handle(Func&& func) {
-    static_assert(std::is_invocable_v<Func, ErrorT>);
     return [
       func = std::forward<Func>(func)
     ] (stateful_error_t<ErrorT>&& e) mutable -> decltype(auto) {
       try {
         std::rethrow_exception(e.ep);
       } catch (const ErrorT& obj) {
-        return std::invoke(std::forward<Func>(func), obj);
+        if constexpr (std::is_invocable_v<Func, decltype(obj)>) {
+          return std::invoke(std::forward<Func>(func), obj);
+        } else {
+          return std::invoke(std::forward<Func>(func));
+        }
       }
       ceph_abort_msg("exception type mismatch – impossible!");
     };