message: Add error handling
Some of the methods that can return errors are not being checked for
errors. Check all of the return values where necessary.
Tested:
Ran through a build and unit test run
Change-Id: I3f8469cbe80a0c58032407f2ba184d913df6e2f1
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/sdbusplus/message.hpp b/sdbusplus/message.hpp
index eb2d49d..30e8d8a 100644
--- a/sdbusplus/message.hpp
+++ b/sdbusplus/message.hpp
@@ -226,7 +226,11 @@
auto get_cookie()
{
uint64_t cookie;
- _intf->sd_bus_message_get_cookie(_msg.get(), &cookie);
+ int r = _intf->sd_bus_message_get_cookie(_msg.get(), &cookie);
+ if (r < 0)
+ {
+ throw exception::SdBusError(-r, "sd_bus_message_get_cookie");
+ }
return cookie;
}
@@ -260,7 +264,11 @@
message new_method_return()
{
msgp_t reply = nullptr;
- _intf->sd_bus_message_new_method_return(this->get(), &reply);
+ int r = _intf->sd_bus_message_new_method_return(this->get(), &reply);
+ if (r < 0)
+ {
+ throw exception::SdBusError(-r, "sd_bus_message_new_method_return");
+ }
return message(reply, std::false_type());
}
@@ -287,7 +295,11 @@
void method_return()
{
auto b = _intf->sd_bus_message_get_bus(this->get());
- _intf->sd_bus_send(b, this->get(), nullptr);
+ int r = _intf->sd_bus_send(b, this->get(), nullptr);
+ if (r < 0)
+ {
+ throw exception::SdBusError(-r, "sd_bus_send");
+ }
}
/** @brief Perform a 'signal-send' call. */