Catch GetSubTreePaths exception
The mapper will throw an exception if the root path passed into it
doesn't exist. Catch that exception instead of crashing and just return
an empty list of PSU paths from the getPSUInventoryPath() function when
/xyz/openbmc_project/inventory doesn't exist.
This showed up due to some timing changes on an IBM system where there
aren't any /xyz/openbmc_project/inventory paths yet when this
application starts.
Tested:
When /xyz/openbmc_project/inventory isn't on D-Bus, the application no
longer crashes.
Change-Id: I45fdc5cd80d7386bb0f8db25474ae53d223bd218
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/src/utils.cpp b/src/utils.cpp
index b583173..0d9d8a0 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -64,14 +64,21 @@
std::vector<std::string> Utils::getPSUInventoryPath(sdbusplus::bus_t& bus) const
{
std::vector<std::string> paths;
- auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
- MAPPER_INTERFACE, "GetSubTreePaths");
- method.append(PSU_INVENTORY_PATH_BASE);
- method.append(0); // Depth 0 to search all
- method.append(std::vector<std::string>({PSU_INVENTORY_IFACE}));
- auto reply = bus.call(method);
+ try
+ {
+ auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
+ MAPPER_INTERFACE, "GetSubTreePaths");
+ method.append(PSU_INVENTORY_PATH_BASE);
+ method.append(0); // Depth 0 to search all
+ method.append(std::vector<std::string>({PSU_INVENTORY_IFACE}));
+ auto reply = bus.call(method);
- reply.read(paths);
+ reply.read(paths);
+ }
+ catch (const sdbusplus::exception_t&)
+ {
+ // Inventory base path not there yet.
+ }
return paths;
}