[PATCH phosphor-objmgr v2 08/10] Add basic error handling to ObjectMapper
OpenBMC Patches
patches at stwcx.xyz
Fri Nov 6 00:21:48 AEDT 2015
From: Brad Bishop <bradleyb at us.ibm.com>
Raise MapperNotFound for invalid paths supplied to the
DBUS API.
---
OpenBMCMapper.py | 4 ++++
phosphor-mapper | 15 ++++++++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/OpenBMCMapper.py b/OpenBMCMapper.py
index 3e7a745..ef49637 100644
--- a/OpenBMCMapper.py
+++ b/OpenBMCMapper.py
@@ -24,6 +24,10 @@ MAPPER_IFACE = MAPPER_NAME + '.ObjectMapper'
MAPPER_PATH = '/org/openbmc/objectmapper/objectmapper'
ENUMERATE_IFACE = 'org.openbmc.Object.Enumerate'
+class MapperNotFoundException(Exception):
+ def __init__(self, msg):
+ super(MapperNotFoundException, self).__init__(msg)
+
class Path:
def __init__(self, path):
self.parts = filter(bool, path.split('/'))
diff --git a/phosphor-mapper b/phosphor-mapper
index 5bdcd8d..e9aa6dc 100644
--- a/phosphor-mapper
+++ b/phosphor-mapper
@@ -133,15 +133,24 @@ class ObjectMapper(dbus.service.Object):
@dbus.service.method(OpenBMCMapper.MAPPER_IFACE, 's', 'a{sas}')
def GetObject(self, path):
- return self.cache[path]
+ o = self.cache.get(path)
+ if not o:
+ raise MapperNotFoundException(path)
+ return o
@dbus.service.method(OpenBMCMapper.MAPPER_IFACE, 'si', 'as')
def GetSubTreePaths(self, path, depth):
- return self.cache.iterkeys(path, depth)
+ try:
+ return self.cache.iterkeys(path, depth)
+ except KeyError:
+ raise MapperNotFoundException(path)
@dbus.service.method(OpenBMCMapper.MAPPER_IFACE, 'si', 'a{sa{sas}}')
def GetSubTree(self, path, depth):
- return { x:y for x, y in self.cache.dataitems(path, depth) }
+ try:
+ return { x:y for x, y in self.cache.dataitems(path, depth) }
+ except KeyError:
+ raise MapperNotFoundException(path)
class BusWrapper:
def __init__(self, bus):
--
2.6.0
More information about the openbmc
mailing list