From cca7a7c8733a22f12d89dc0fd2d355f4fb9b4bb4 Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Mon, 9 Jul 2018 22:34:33 -0400 Subject: propertywatch: Improve error handling Handle exceptions from the sdbusplus method call API. A number of method calls are made at application startup. First the mapper is queried and then host services directly to obtain initial values for the property cache. In either case a missing object is sometimes expected and tolerated (in a logical sense) without issue. Eat the new exceptions in these scenarios and avoid a program crash. Change-Id: Id79d28b2da997f3c545b86c21932e271e3df8bb3 Signed-off-by: Brad Bishop --- src/propertywatchimpl.hpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/propertywatchimpl.hpp') diff --git a/src/propertywatchimpl.hpp b/src/propertywatchimpl.hpp index 003ee37..6500a15 100644 --- a/src/propertywatchimpl.hpp +++ b/src/propertywatchimpl.hpp @@ -47,11 +47,22 @@ void PropertyWatch::start() // Do a query to populate the cache. Start with a mapper query. // The specific services are queried below. - const std::vector queryInterfaces; // all interfaces - auto mapperResp = - DBusInterfaceType::template callMethodAndRead( - MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, "GetObject", - path, queryInterfaces); + auto getObjectFromMapper = [](const auto& path) { + const std::vector queryInterfaces; // all interfaces + try + { + return DBusInterfaceType::template callMethodAndRead( + MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, "GetObject", + path, queryInterfaces); + } + catch (const sdbusplus::exception::SdBusError&) + { + // Paths in the configuration may not exist yet. Prime those + // later, when/if InterfacesAdded occurs. + return GetObject(); + } + }; + auto mapperResp = getObjectFromMapper(path); for (const auto& i : interfaces) { @@ -87,7 +98,16 @@ void PropertyWatch::start() } // Delegate type specific property updates to subclasses. - updateProperties(busName, path, interface); + try + { + updateProperties(busName, path, interface); + } + catch (const sdbusplus::exception::SdBusError&) + { + // If for some reason the path has gone away since + // the mapper lookup we'll simply try again if/when + // InterfacesAdded occurs the next time it shows up. + } } } } -- cgit v1.2.1