Improve error handling for exceptions and asserts
The phosphor-psu-code-manager application currently exits abnormally due
to the following conditions:
* Uncaught exception
* False assert() statement
An abnormal exit can result in a core dump and/or a BMC dump. It also
causes the service to be restarted. If the failure condition remains,
the restarts will fail repeatedly, and systemd will stop trying to start
the service.
Improve error handling for exceptions in the following ways:
* Add try/catch blocks to the following locations:
* Code that calls functions that throw and needs to handle exceptions.
* For example, code looping over PSU objects may need to handle an
exception for one PSU and then continue to the remaining PSUs.
* D-Bus PropertiesChanged and InterfacesAdded event handlers.
* Do not allow exceptions to escape to the sdbusplus stack frames.
* main()
* Last line of defense; catching avoids a core dump.
* Write exception error message to the journal if appropriate
Replace assert statements with exceptions or error messages to the
journal.
Tested:
* Tested all modified functions/methods.
* Verified that all exceptions were caught and logged to the journal if
appropriate.
* Verified that asserts were replaced by exceptions and logging.
* See complete test plan at
https://gist.github.com/smccarney/b4bf568639fedd269c9737234fa2803d
Change-Id: I933386e94f43a915b301d6aef7d91691816a0548
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/src/utils.hpp b/src/utils.hpp
index 020d528..2ce64f4 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -24,12 +24,22 @@
const UtilsInterface& getUtils();
/**
- * @brief Get PSU inventory object path from DBus
+ * @brief Get PSU inventory object paths from DBus
+ *
+ * @details The returned vector will be empty if an error occurs or no paths are
+ * found.
+ *
+ * @param[in] bus - The Dbus bus object
+ *
+ * @return PSU inventory object paths that were found (if any)
*/
std::vector<std::string> getPSUInventoryPaths(sdbusplus::bus_t& bus);
/** @brief Get service name from object path and interface
*
+ * @details Throws an exception if an error occurs or no service name was
+ * found.
+ *
* @param[in] bus - The Dbus bus object
* @param[in] path - The Dbus object path
* @param[in] interface - The Dbus interface
@@ -39,19 +49,24 @@
std::string getService(sdbusplus::bus_t& bus, const char* path,
const char* interface);
-/** @brief Get all the service names from object path and interface
+/** @brief Get all service names from object path and interface
+ *
+ * @details The returned vector will be empty if no service names were found.
+ * Throws an exception if an error occurs.
*
* @param[in] bus - The Dbus bus object
* @param[in] path - The Dbus object path
* @param[in] interface - The Dbus interface
*
- * @return The name of the services
+ * @return The name of the services (if any)
*/
std::vector<std::string> getServices(sdbusplus::bus_t& bus, const char* path,
const char* interface);
/** @brief The template function to get property from the requested dbus path
*
+ * @details Throws an exception if an error occurs
+ *
* @param[in] bus - The Dbus bus object
* @param[in] service - The Dbus service name
* @param[in] path - The Dbus object path
@@ -96,7 +111,8 @@
*
* @param[in] versions - The list of the versions
*
- * @return The latest version string
+ * @return The latest version string, or empty string if it fails to get the
+ * latest version
*/
std::string getLatestVersion(const std::set<std::string>& versions);