diff options
-rw-r--r-- | include/ipmid/handler.hpp | 68 | ||||
-rw-r--r-- | include/ipmid/message.hpp | 4 | ||||
-rw-r--r-- | test/message/payload.cpp | 15 |
3 files changed, 53 insertions, 34 deletions
diff --git a/include/ipmid/handler.hpp b/include/ipmid/handler.hpp index ebeb442..c84bffd 100644 --- a/include/ipmid/handler.hpp +++ b/include/ipmid/handler.hpp @@ -179,45 +179,47 @@ class IpmiHandler final : public HandlerBase * parameter selector. All the remaining data can be extracted using * the Payload class and the unpack API available to the Payload class. */ - std::optional<InputArgsType> inputArgs; - if constexpr (std::tuple_size<InputArgsType>::value > 0) + ResultType result; + try { - if constexpr (std::is_same<std::tuple_element_t<0, InputArgsType>, - boost::asio::yield_context>::value) - { - inputArgs.emplace(std::tuple_cat( - std::forward_as_tuple(*(request->ctx->yield)), - std::move(unpackArgs))); - } - else if constexpr (std::is_same< - std::tuple_element_t<0, InputArgsType>, - ipmi::Context::ptr>::value) - { - inputArgs.emplace( - std::tuple_cat(std::forward_as_tuple(request->ctx), - std::move(unpackArgs))); - } - else if constexpr (std::is_same< - std::tuple_element_t<0, InputArgsType>, - ipmi::message::Request::ptr>::value) + std::optional<InputArgsType> inputArgs; + if constexpr (std::tuple_size<InputArgsType>::value > 0) { - inputArgs.emplace(std::tuple_cat(std::forward_as_tuple(request), - std::move(unpackArgs))); + if constexpr (std::is_same< + std::tuple_element_t<0, InputArgsType>, + boost::asio::yield_context>::value) + { + inputArgs.emplace(std::tuple_cat( + std::forward_as_tuple(*(request->ctx->yield)), + std::move(unpackArgs))); + } + else if constexpr (std::is_same< + std::tuple_element_t<0, InputArgsType>, + ipmi::Context::ptr>::value) + { + inputArgs.emplace( + std::tuple_cat(std::forward_as_tuple(request->ctx), + std::move(unpackArgs))); + } + else if constexpr (std::is_same< + std::tuple_element_t<0, InputArgsType>, + ipmi::message::Request::ptr>::value) + { + inputArgs.emplace(std::tuple_cat( + std::forward_as_tuple(request), std::move(unpackArgs))); + } + else + { + // no special parameters were requested (but others were) + inputArgs.emplace(std::move(unpackArgs)); + } } else { - // no special parameters were requested (but others were) - inputArgs.emplace(std::move(unpackArgs)); + // no parameters were requested + inputArgs = std::move(unpackArgs); } - } - else - { - // no parameters were requested - inputArgs = std::move(unpackArgs); - } - ResultType result; - try - { + // execute the registered callback function and get the // ipmi::RspType<> result = std::apply(handler_, *inputArgs); diff --git a/include/ipmid/message.hpp b/include/ipmid/message.hpp index b10fc42..9bc1147 100644 --- a/include/ipmid/message.hpp +++ b/include/ipmid/message.hpp @@ -18,6 +18,7 @@ #include <algorithm> #include <boost/asio/spawn.hpp> #include <cstdint> +#include <exception> #include <ipmid/api-types.hpp> #include <ipmid/message/types.hpp> #include <memory> @@ -110,7 +111,8 @@ struct Payload ~Payload() { using namespace phosphor::logging; - if (raw.size() != 0 && !trailingOk && !unpackCheck && !unpackError) + if (raw.size() != 0 && std::uncaught_exceptions() == 0 && !trailingOk && + !unpackCheck && !unpackError) { log<level::ERR>("Failed to check request for full unpack"); } diff --git a/test/message/payload.cpp b/test/message/payload.cpp index 431a34b..56d8d41 100644 --- a/test/message/payload.cpp +++ b/test/message/payload.cpp @@ -19,6 +19,7 @@ #include <ipmid/api.hpp> #include <ipmid/message.hpp> +#include <stdexcept> #include <gtest/gtest.h> @@ -425,3 +426,17 @@ TEST_F(PayloadLogging, EnforcingMove) } EXPECT_EQ(logs.size(), 1); } + +TEST_F(PayloadLogging, EnforcingException) +{ + try + { + ipmi::message::Payload p({1, 2}); + p.trailingOk = false; + throw std::runtime_error("test"); + } + catch (...) + { + } + EXPECT_EQ(logs.size(), 0); +} |